I'm looking for best practices on services, controllers and directives for Angularjs 1.3.X.
Here is the rules i noticed :
- The view (html) knows only the main controller and his scope
- A directive should not have his own services
So :
- The view (html) cannot call the services directly.
- The view (html) must use the main controller to access the services.
- The view must declare the binding between the directive and the main controller
And then :
In the code, if a directive have to call a business function F1 of services :
- the main controller must publish a function F2 which wrap the function F1
- the view must declare F2 in the directive configuration
You can look at the picture attached for a more visual explaination.
Questions :
- Are you agree with those rules and the style of code ?
- Do you have any additional rules ?
- Why should we not follow these rules ?
