A
A
Abc Edc2015-07-17 19:25:19
Angular
Abc Edc, 2015-07-17 19:25:19

How independent should a directive be?

That is, should it inject services for requests into itself? Is it necessary to put even the usual output of materials into directives, and what then remains on the controller?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey, 2015-07-17
@gleber1

what then remains on the controller?

And nothing will remain, and nothing much should remain (except perhaps a little bit). Even your controller that you declare for the state is essentially nothing more than the controller of the ng-view/ui-view/ng-controller directive.
Everything is divided into directives, the more independent the better. Let's say if we have a block with a feed of recent events - this is a separate directive, a service for receiving data is injected into it. You can also make a separate feed item a directive and put things in there - for example, likes or deletion or editing (respectively, you need to inject services there to manage this business).
Well, each directive has its own controller, use the scope only in the link (actually like watchers) and in the link only connect the DOM and the controller. Something like this. And it will be a little easier to live with Angular.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question