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

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

问题描述

我想在 Angular 2 中创建一个属性指令.它需要在其主机上有一个点击处理程序.在评估元素上的其他指令之前需要添加点击处理程序,因为它控制对某些功能的访问.在 Angular 1 中,您可以在创建指令时使用优先级选项执行此操作.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天全站免登陆