I am looking for best practices for services, controllers and directives for Angularjs 1.3.X.
Here are the rules that I noticed:
- View (html) knows only the main controller and its scope
- The directive should not have its own services
So:
- View (html) cannot directly call services.
- The view (html) must use the main controller to access the services.
- The view must declare a binding between the directive and the main controller.
And then:
In the code, if the directive should call the business function F1 of the services:
- the main controller should publish the function F2, which terminates the function F1
- the view should declare F2 in the configuration of the directive
You can see the image attached for a more visual explanation.
Questions:
- Do you agree with these rules and code style?
- Do you have additional rules?
“Why shouldn't we follow these rules?”

source
share