Angularjs múltiples controladores para un objeto
Frecuentes
Visto 49 veces
0
Let's take for example this(user edit) page:
http://img38.imageshack.us/img38/6032/4gg6.png
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)?
¡Gracias!
1 Respuestas
1
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 angularjs or haz tu propia pregunta.
your can write on controller and three directives(PersonalDataEdit,ContactsEdit,SomeOtherDataEdit) - Kain
And I would add that you should put your data (the user) in a service that you inject everywhere you need it. - maxdec