Angular 2 中指令评估的控制顺序

编程入门 行业动态 更新时间:2024-10-27 15:28:27
本文介绍了Angular 2 中指令评估的控制顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我想在 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屋!

更多推荐

[db:关键词]

本文发布于:2023-04-22 23:08:42,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1031223.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:指令   顺序   Angular

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!