Controlling order of directive evaluation in Angular 2

前端 未结 2 879
攒了一身酷
攒了一身酷 2021-01-18 06:41

I want to create an attribute directive in Angular 2. It needs to have a click handler on its host. The click handler needs to be added before the other directives on the el

相关标签:
2条回答
  • 2021-01-18 07:05

    priority in Angular 2 is not supported, and there isn't any plan to add it.

    Component directives may not use the following attributes:

    priority and terminal. While Angular 1 components may use these, they are not used in Angular 2 and it is better not to write code that relies on them.

    See https://angular.io/docs/ts/latest/guide/upgrade.html#!#using-component-directives

    0 讨论(0)
  • 2021-01-18 07:15

    I found that the order the directives are evaluated in in Angular 2 can be defined in the declarations block of the ngModule decorator. Like this:

    @NgModule({
        imports: [BrowserModule], 
        // SecondDirective will be evaluated before FirstDirective
        declarations: [AppComponent, SecondDirective, FirstDirective],
        bootstrap: [AppComponent]
    })
    
    0 讨论(0)
提交回复
热议问题