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

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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 03:08