Controlling order of directive evaluation in Angular 2

你离开我真会死。 提交于 2019-12-01 17:49:59
Mark Kennedy

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

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]
})
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!