asicfr
asicfr

Reputation: 1061

Angularjs best architecture

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 ?

enter image description here

Upvotes: 3

Views: 1023

Answers (1)

Ceryni
Ceryni

Reputation: 441

those are most popular styling guides and well discussed in my opinion (all three are collaborating):

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 those. you might want to take a closer look to them

Upvotes: 1

Related Questions