1

Is there a convention when I should create a new controller in my page?

Is it something like 1 controller per page? PageController

Or something like HeaderController, NavigationController and FooterController which is per component?

Any helpful resource will also help. Thanks a lot!

2
  • There is a section on where to use a controller here: Docs Commented Oct 19, 2015 at 10:10
  • Rule of thumb: whenever an individual element is complex enough to warrant its dedicated controller, and/or any element which is independent of other elements and can be controlled by itself. Commented Oct 19, 2015 at 10:19

2 Answers 2

2

It is better to create one controller for the page content, and one for each component repeated on the page (navbar, footer ...), in order to be reused on other page.

Bests practices here : https://scotch.io/tutorials/angularjs-best-practices-directory-structure (see "modularize" and "components")

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

Comments

0

I can't find anything to justify my claims so just count on my 2+ years of experience in angular.

These are the cases where I would create a new controller: 1. A new view in the app. 2. A reusable piece of code (can be integrated with a directive). 3. When there's a lot of logic in a view controller I usually create 'sub-controllers' just so it becomes more lean.

Final say about controller - Angular2 & React are saying goodbye to controllers, so I'd recommend to move controller logic either to services or directives.

Cheers

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.