Chapter 6. Directives in Detail

Directives live in the view. Directives are likely the hardest part of AngularJS to grasp, but also likely the most powerful. If you can understand how to write a directive, you can save yourself writing a lot of markup. Directives essentially extend HTML and you can use them to create your own DSL (domain-specific language).

Directives are not injectable.  There is no sane way to access the behavior of a directive, and if you feel you need to, you're doing it wrong.  They are meant to be put in the view and the view only.  Unlike filters, which mainly live in the view, there is no handy $directive service to grab one.  If you want one, you'll have to put it in some markup and compile and/or link your markup (which ...

Get Developing an AngularJS Edge now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.