从8.1更新到8.2后,我会收到很多类似的错误
MyComponent.html:6 ERROR TypeError: Cannot read property 'ngInjectableDef' of undefined
at getInjectableDef (core.js:361)
at resolveNgModuleDep (core.js:30377)
at NgModuleRef_.get (core.js:31578)
at injectInjectorOnly (core.js:734)
at ɵɵinject (core.js:744)
at injectArgs (core.js:837)
at core.js:16346
at _callFactory (core.js:30486)
at _createProviderInstance (core.js:30429)
at resolveNgModuleDep (core.js:30388)```
答案 0 :(得分:1)
我发现了一个原因...
我有很多这样的地方
export class AbstractSth {
constructor(protected service: SomeService) {}
}
export class SpecialSth extends AbstractSth {
// ... special stuff (no constructor needed in 8.1)
}
事实证明,在8.2版本中,SpecialSth类需要通过super()调用自己的构造函数,因为现在不知何故,只有子类获得了所需的属性注入,而没有构造函数却没有注入任何东西,而继承的父构造函数似乎在注入逻辑中被忽略。
所以这解决了这个问题:
export class SpecialSth extends AbstractSth {
constructor(protected service: SomeService) {
super(service);
}
// ... special stuff
}