Best Angularjs Architecture

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

enter image description here

+4
source share
1 answer

these are the most popular style guides and are well discussed in my opinion (all three work together):

https://github.com/johnpapa/angular-styleguide

https://github.com/jmcunningham/angularjs-styleguide

https://github.com/toddmotto/angularjs-styleguide

short answer: your approach seems very similar to them. you may need to take a closer look at them.

+1
source

All Articles