for directives that rely on DOM manipulation, adding event listeners etc, because the compile and link functions are unavailable
when you need advanced directive definition options like priority, terminal, multi-element
when you want a directive that is triggered by an attribute or CSS class, rather than an element
I didn't know that you couldn't introduce a link function. A few of my directives leverage the link function. I originally thought that all directives can be rewritten into components or am I wrong on this?
Components are essentially Controller + Template, with isolate scope as defaults (and a few other things) and the ability to pass data in. Directives will "decorate" the DOM, such as ng-repeat, rather than defining a new template. You might find some tips here: https://toddmotto.com/exploring-the-angular-1-5-component-method
10
u/saladfingers6 Feb 05 '16
Time to refactor those directives! :)
Todd Motto wrote a fine pattern with explanation: https://www.reddit.com/r/angularjs/comments/43l0yv/1x_component_what_would_john_papa_do/czjq5e0