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)?

Thank You!

2
  • 2
    your can write on controller and three directives(PersonalDataEdit,ContactsEdit,SomeOtherDataEdit) Commented Nov 15, 2013 at 8:44
  • 1
    And I would add that you should put your data (the user) in a service that you inject everywhere you need it. Commented Nov 15, 2013 at 10:12

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.