简体   繁体   English

Angular 库基础 class 没有任何装饰器但使用 Angular 功能

[英]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.

相关问题 如何在不出错的情况下实现 OnInit:Class 正在使用 Angular 功能但未进行装饰。 请添加显式 Angular 装饰器 - How do I implement OnInit without getting error: Class is using Angular features but is not decorated. Please add an explicit Angular decorator 问:Angular 组件损坏 - “类正在使用 Angular 功能但未装饰。请添加显式 Angular 装饰器” - Q: Angular components broken - "Class is using Angular features but is not decorated. Please add an explicit Angular decorator" 类使用 Angular 特性但没有修饰。 请添加一个显式的 Angular 装饰器 - Class is using Angular features but is not decorated. Please add an explicit Angular decorator Class 正在使用 Angular 功能,但未在 angular 14 中进行修饰 - Class is using Angular features but is not decorated in angular 14 Class 正在使用 Angular 功能但未使用 Typescript 4.8.2 进行装饰 - Class is using Angular features but is not decorated with Typescript 4.8.2 Angular 10 model class 装饰器? - Angular 10 model class decorator? 在类中没有装饰器的Angular 2服务注入 - Angular 2 service injection in class with no decorator 打字机未导入角装饰器“类” - Angular decorator “class” not imported by typescript 在Angular 2中在组件之间传递变量而不使用@Input装饰器 - Passing variables between components without using @Input decorator in Angular 2 在 Angular 输入装饰器中使用装饰器 - Using a decorator inside an Angular input decorator
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM