带有@Injectable()的Angular 9 BaseComponent

问题描述:

在Angular 8中,我能够使用"@Injectable"属性创建基本组件(对实际组件的继承进行分类). Angular 9编译器告诉我:

In Angular 8 I was able to create base components (classes the actual component inhert from) with an "@Injectable" attribute. The Angular 9 compiler tells me:

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

The component YourComponent inherits its constructor from BaseComponent, but the latter does not have an Angular decorator of its own. Dependency injection will not be able to resolve the parameters of BaseComponent's constructor. Either add a @Directive decorator to BaseComponent, or add an explicit constructor to RoleSelectDialogComponent.

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

What is the Angular 9 way of doing these things now? This works but looks somehow hacky:

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

提示在消息中

Either add a @Directive decorator to BaseComponent

向其添加@Directive()应该可以解决问题.

Adding a @Directive() to it should do the trick.

我现在正在进行升级,我的基本组件会自动添加@Directive()装饰器.

I'm just going through an upgrade now, and my base component automatically has the @Directive() decorator added.