带有@Injectable()的Angular 9 BaseComponent [英] Angular 9 BaseComponent with @Injectable()

查看:196
本文介绍了带有@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.

这篇关于带有@Injectable()的Angular 9 BaseComponent的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆