javascript - Components and directives in angular 1.5 -


the big feature changes in angular 1.5 surrounding support of components.

component('mycomponent', {   template: '<h1>hello {{ $ctrl.getfullname() }}</h1>',   bindings: { firstname: '<', lastname: '<' },   controller: function() {     this.getfullname = function() {       return this.firstname + ' ' + this.lastname;     };   } }); 

while good, not sure how differs directives. benefits of using components on traditional custom directives? , components in angular 1.5 , angular 2 same?

the .component preferred way of writing code because favors practices , gives developers ability write code in angular 2 (similar web components). basically, when write code using component, upgrading angular 2 easier. functionalities remains same. should use .component always when possible.

changes (extract)

  • component declared using object instead of function
  • simplified isolated scope using binding property
  • components isolated scope
  • some bad practices not possible
  • simpler, easier understand configuration
  • lifecycle hooks: ($oninit(), $onchanges(changesobj), $docheck(), $ondestroy(), $postlink())

awesome article here: https://toddmotto.com/exploring-the-angular-1-5-component-method

when not use components (from docs):

  • for directives need perform actions in compile , pre-link functions, because aren't available
  • when need advanced directive definition options priority, terminal, multi-element
  • when want directive triggered attribute or css class, rather element.

i believe, the best description can find official guide: https://docs.angularjs.org/guide/component. covers changes, reasons changes , gives deep understanding of components.


Comments

Popular posts from this blog

routing - AngularJS State management ->load multiple states in one page -

python - GRASS parser() error -

Swift game error message -