[英]Angular Library base class without any decorator but using Angular features
I came across this in the Angular migration guide.我在 Angular 迁移指南中遇到了这个问题。
https://angular.io/guide/migration-undecorated-classes https://angular.io/guide/migration-undecorated-classes
I'm a library author.
我是图书馆作者。 Should I add the @Directive() decorator to base classes?
我应该将 @Directive() 装饰器添加到基类吗?
As support for selectorless decorators is introduced in Angular version 9, if you want to support Angular version 8 and earlier, you shouldn't add a selectorless @Directive() decorator.
由于 Angular 版本 9 中引入了对无选择器装饰器的支持,如果您想支持 Angular 版本 8 及更早版本,则不应添加无选择器 @Directive() 装饰器。 You can either add @Directive() with a selector or move the Angular-specific features to affected subclasses.
您可以使用选择器添加 @Directive() 或将特定于 Angular 的功能移动到受影响的子类。
I then checked our code library to find that there are some base classes that still don't have any decorators but is running in Angular V11.然后我检查了我们的代码库,发现有些基类仍然没有任何装饰器,但在 Angular V11 中运行。 I don't see any compile errors nor linting errors.
我没有看到任何编译错误或 linting 错误。
There are many such base classes that uses angular features, hostbinding etc but still without a decorator.有许多这样的基类使用 angular 特性、主机绑定等,但仍然没有装饰器。 Is there a linting rule or some way with which we can catch these?
是否有 linting 规则或某种方法可以捕捉到这些?
I later figured out that with Ivy Compiler such classes without decorators are caught at compile time: NG2007: Class is using Angular features but is not decorated.
后来我发现,使用 Ivy 编译器,这样的没有装饰器的类在编译时会被捕获: NG2007: Class 正在使用 Angular 功能,但没有装饰。
Please add an explicit Angular decorator.
请添加一个显式的 Angular 装饰器。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.