r/angularjs • • Feb 05 '16

Angular 1.5 released!

https://github.com/angular/angular.js/blob/master/CHANGELOG.md?=1.5
96 Upvotes

36 comments sorted by

View all comments

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

3

u/NYKHouston43 Feb 05 '16

I actually saw this recently in the AngularJS docs: https://docs.angularjs.org/guide/component

When not to use Components:

  • 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?

3

u/toddmotto Feb 05 '16

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