首页 > 解决方案 > 带有 @Injectable() 的 Angular 9 BaseComponent

问题描述

在 Angular 8 中,我能够使用“@Injectable”属性创建基础组件(实际组件继承自的类)。Angular 9 编译器告诉我:

组件 YourComponent 从 BaseComponent 继承其构造函数,但后者没有自己的 Angular 装饰器。依赖注入将无法解析 BaseComponent 的构造函数的参数。向 BaseComponent 添加一个 @Directive 装饰器,或者向 RoleSelectDialogComponent 添加一个显式构造函数。

现在 Angular 9 做这些事情的方式是什么?这可行,但看起来有点hacky:

@Component({
    selector: 'baseComponent',
    template: 'no-ui'
})

标签: angularangular9

解决方案


线索在消息中

Either add a @Directive decorator to BaseComponent

向它添加 @Directive() 应该可以解决问题。

我现在正在升级,我的基础组件自动添加了 @Directive() 装饰器。


推荐阅读