控制Angular 2中指令评估的顺序 [英] Controlling order of directive evaluation in Angular 2

查看:95
本文介绍了控制Angular 2中指令评估的顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Angular 2中创建一个属性指令。它需要在其主机上有一个单击处理程序。在评估元素上的其他指令之前,需要添加单击处理程序,因为它控制对某些功能的访问。在Angular 1中,您可以在创建指令时使用priority选项执行此操作。在Angular 2中是否存在某种等价物?

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 element are evaluated because it controls access to certain functionality. In Angular 1, you could do this with the priority option when creating a directive. Is there some sort of equivalent in Angular 2?

谢谢,
追逐

推荐答案

我发现在Angular 2中评估指令的顺序可以在ngModule装饰器的声明块中定义。像这样:

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]
})

这篇关于控制Angular 2中指令评估的顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆