I was wanting to get peoples feedback with regards to creating controllers. Before I just had a few controllers but recently I have broken these out into many more controllers so I get better separation and maintenance...
But I am unsure if this was a good idea!
How many controllers are classes as too many?
For example, before I had a page that show 1 table and an inner table. So I had 1 controller before and now I have added another controller so that 1 controller manages the outer table and the other the inner controller.
Also navigation and sub navigation, I am now using a number of controllers for this where as before I was using just one controller.
is this best practice?
Thanks in advance
An AngularJS application can contain one or more controllers as needed, in real application a good approach is to create a new controller for every significant view within the application.
It is tempting to do too much work in the AngularJS controller. After all, the controller is where the view first has access to JavaScript via $scope functions. However, doing this will cause you to miss out on code sharing across the site and is not recommended by AngularJS documentation.
The '$timeout' service of AngularJS is functionally similar to the 'window. setTimeout' object of vanilla JavaScript. This service allows the developer to set some time delay before the execution of the function.
$watch() function is used to watch the changes of variables in $scope object. Generally the $watch() function will create internally in Angularjs to handle variable changes in application.
I think this blog post by Vlad Orlenko is a good take on how to structure a big angular project: AngularJS Best Practices: I’ve Been Doing It Wrong! Part 1 of 3
Skip right to the "Layout of src: feature-based modularization"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With