AngularJS a lot of listeners in directive

I know that any DOM manipulations should be done via directives and not in controllers.
By now I have about 10 listeners in my accordion directive, reacting on adding/deleting item, activating, etc. Also I've got many events in my controller.

  • I wonder if it is OK to (ab)use this kind of interaction?
  • Maybe it is better to have many directives handling 1 listener and use them passing certain parameters?

Sorry for such a vague question, just want to know what is the real 'angular' way.

Directives are not supposed to know about each other, unless they have some sort of hierarchy between them or a designed interactive behavior, so sharing listeners would be cumbersome. Even if they did know of each other, it is not customary to share listeners. If you don't have a performance or memory issue, then you don't have a problem to solve.

Have you ever tried to open firefly or Chrome's developer tools and see how many event handlers are registered for some elements? Lots! There are hundreds of listeners active at any given time in the entire DOM (and not just for AngularJs, mind you). Besides, the only thing you would reduce is event listener references, not the functionality executed as a result of an event.

So don't worry about those 10 listeners you have now. However, if we had a concrete example, we might be able to help alliviate some event handlers, by using the $scope instead (through $watch, or $observe or some property another directive is already setting).


As a sidenote, if you do have a high cohesion between directives or controllers:

You are probably having too much logic in your directives/controllers where you rely a lot on the $scope for sharing data. In these cases you should consider simplifying the directives and moving state-reliant logic to a service. Avoid over-reliance on Scope.