Angular update 8.1 to 8.2 I get many “Cannot read property 'ngInjectableDef' of undefined”

元气小坏坏 提交于 2020-03-25 19:22:07

问题


After updating from 8.1 to 8.2 I get many errors like this

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)```



回答1:


I found one reason...

I had many places like this

export class AbstractSth {
    constructor(protected service: SomeService) {}
}

export class SpecialSth extends AbstractSth {
    // ... special stuff (no constructor needed in 8.1)
}

Well it turned out that with 8.2 the SpecialSth class needs its own constructor with a super() call, because somehow now only the child class gets the needed properties injected and with no constructor nothing is injected and the inherited parent constructor seems to be ignored in the injection logic.

So this fixes the problem:

export class SpecialSth extends AbstractSth {
    constructor(protected service: SomeService) {
        super(service);
    }
    // ... special stuff
}


来源:https://stackoverflow.com/questions/59271316/angular-update-8-1-to-8-2-i-get-many-cannot-read-property-nginjectabledef-of

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!