【发布时间】:2020-10-12 20:22:33
【问题描述】:
我已经构建了一个demo,它创建了 2 个自定义角度元素(结帐 app.module)。像魅力一样工作,但有一个问题,如果我在父元素(称为 BarComponent)中提供服务,它的子 CE(称为 TestComponent)不会收到它
@Component({
templateUrl: './bar-ce.component.html',
providers: [TestService] // <-- this one!!
})
export class BarComponent {}
在其 html 中呈现子 CE:TEST-CE: <test-ce></test-ce>
如果我尝试以这种方式注入我的 TestService,我会得到“NullInjectorError: No provider for TestService!”
但如果我在 app.module 中提供它,一切都会再次运行。所以我的问题是,有没有办法解决这个问题,或者这只是 CE 的方式(希望不是)?
【问题讨论】:
标签: angular dependency-injection custom-element angular-dependency-injection