Angularjs múltiples controladores para un objeto

Let's take for example this(user edit) page:

and the controller for this page:

function userEditCtrl($scope) {
    $scope.user = {
        personalData: {
            firstName: '...',
            lastName: '...'  
        contacts: [{}, {}, {}],
        someOtherData: {
            field: 'value'    

in the page we have 3 sections (personal data, contacts and some other data), in the user object we also have corresponding fields.

what is the best practice for creating separate controller for every section (userPersonalDataEditCtrl, userContactsEditCtrl, userSomeOtherDataEditCtrl)?


preguntado el 15 de noviembre de 13 a las 08:11

your can write on controller and three directives(PersonalDataEdit,ContactsEdit,SomeOtherDataEdit) -

And I would add that you should put your data (the user) in a service that you inject everywhere you need it. -

1 Respuestas

Best approach is create 3 different controller and directive for each this controller, because you have 3 independent sections. Each controller must work only with its own directive.

respondido 15 nov., 13:11

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.