简体   繁体   English

如何在Angular中防止两个不兼容的指令分配给同一元素?

[英]How can I prevent, in Angular, two incompatible directives to be assigned to the same element?

I have to similar directives that shouldn't be added to the same HTML element to avoid weird behaviour. 我必须避免将类似的指令添加到同一HTML元素中,以免发生怪异的行为。

Is there any standard way to establish to directives as incompatible or to check whether these to directives are assigned to the same element and throw an error or a warning? 是否有任何标准方法可以将指令伪指令建立为不兼容或检查是否将这些指令伪指令分配给同一元素并引发错误或警告?

You could achieve that with a custom rule in linter such as eslint. 您可以使用诸如lslint之类的linter中的自定义规则来实现。 Configure it as error and the linting will fail when the rule is met. 将其配置为错误,并且在满足规则时,插入操作将失败。 I believe it's a better approach than trying to detect it in the code of the directives themselves during runtime. 我认为,这比在运行时尝试在指令本身的代码中检测到它更好。 There are plenty of resources discussing custom eslint rules such as https://flexport.engineering/writing-custom-lint-rules-for-your-picky-developers-67732afa1803 有大量资源讨论自定义eslint规则,例如https://flexport.engineering/writing-custom-lint-rules-for-your-picky-developers-67732afa1803

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM