Application Architecture: Directives vs. Controllers

I have a great application that contains many layouts and subheadings. It looks like (simplified): http://plnkr.co/edit/x4kleCCQH5Hsy6dcjgXe?p=preview

So, I have many directives and services. And only 2-4 simple controllers (10-20 lines of code). All logic is stored in large directives that contain many small directives. I am wrong?

+8
angularjs
source share
3 answers

I approach him.

  • Directives contain browsing logic, not business logic. This also happens when DOM-messing occurs, if necessary.

  • The controllers are pretty thin, have minimal business logic.

  • Angular Services where most of the heavy lifting is done.

If you have logic that needs to be reused by several areas / controllers or is well-founded - perhaps it is better suited for use in the Service than in the Directive.

Depending on your application / architecture, you can send messages to the server and have a heavy BL on the server side.

There is a nice bit to Angular docs on Correctly using directives , which has a few pointers.

+7
source share
0
source share

The link was blocked ... a working link to the same directory is here: http://docs.angularjs.org/guide/controller

0
source share

All Articles