Hi Elias,
I've been trying to build a minimum reproducible test case for days with no
success, I'm currently running into another issue which might or might not
be related at all.
before bootstrapping the application :
import { test } from "app/test";
console.log("pre-test");
test();
console.log("post-test");
test.ts:
import {
Inject,
Injectable,
Injector,
LOCALE_ID,
ReflectiveInjector,
} from "@angular/core";
import {
ExternalBaseClass,
} from "./test2";
export abstract class LocalBaseClass {
protected a: string;
constructor(@Inject(Injector) protected _injector: Injector) {
console.log(`${this.constructor.name}[LocalBaseClass] _injector`,
_injector);
console.log(`${this.constructor.name}[LocalBaseClass] this._injector`,
this._injector);
this.a = this._injector.get(LOCALE_ID);
}
}
@Injectable()
class CustomProvider extends LocalBaseClass {}
@Injectable()
class Custom2Provider extends ExternalBaseClass {}
export function test() {
console.log("step 1");
const injector = ReflectiveInjector.resolveAndCreate([
CustomProvider,
Custom2Provider,
{ provide: LOCALE_ID, useValue: "fr" }
]);
console.log("step 2");
let customProvider = injector.get(CustomProvider);
console.log("step 3");
let custom2Provider = injector.get(Custom2Provider);
console.log("step 4");
}
test2.ts:
import {
Inject,
Injector,
LOCALE_ID,
} from "@angular/core";
export abstract class ExternalBaseClass {
protected a: string;
constructor(@Inject(Injector) protected _injector: Injector) {
console.log(`${this.constructor.name}[ExternalBaseClass] _injector`,
_injector);
console.log(`${this.constructor.name}[ExternalBaseClass]
this._injector`, this._injector);
this.a = this._injector.get(LOCALE_ID);
}
}
Console output :
pre-test
12:22:55.568 test.ts:31 step 1
12:22:55.571 test.ts:37 step 2
12:22:55.573 test.ts:19 CustomProvider[LocalBaseClass] _injector
ReflectiveInjector_ {_constructionCounter: 1, _providers: Array(3), parent:
null, keyIds: Array(3), objs: Array(3)}
12:22:55.575 test.ts:20 CustomProvider[LocalBaseClass] this._injector
ReflectiveInjector_ {_constructionCounter: 1, _providers: Array(3), parent:
null, keyIds: Array(3), objs: Array(3)}
12:22:55.577 test.ts:39 step 3
12:22:55.581 test2.ts:11 Custom2Provider[ExternalBaseClass] _injector
undefined
12:22:55.583 test2.ts:12 Custom2Provider[ExternalBaseClass] this._injector
undefined
12:22:55.584 core.js:1747 Uncaught Error: Cannot read property 'get' of
undefined: Error during instantiation of Custom2Provider!. caused by: Cannot
read property 'get' of undefined
at wrappedError (core.js:1747)
at injectionError (core.js:1781)
at instantiationError (core.js:1866)
at ReflectiveInjector_.push.../../../../node_modules/@angular/core/fesm5
/core.js.ReflectiveInjector_._instantiate (core.js:2523)
at ReflectiveInjector_.push.../../../../node_modules/@angular/core/fesm5
/core.js.ReflectiveInjector_._instantiateProvider (core.js:2501)
at ReflectiveInjector_.push.../../../../node_modules/@angular/core/fesm5
/core.js.ReflectiveInjector_._new (core.js:2489)
at ReflectiveInjector_.push.../../../../node_modules/@angular/core/fesm5
/core.js.ReflectiveInjector_._getObjByKeyId (core.js:2545)
at ReflectiveInjector_.push.../../../../node_modules/@angular/core/fesm5
/core.js.ReflectiveInjector_._getByKeyDefault (core.js:2577)
at ReflectiveInjector_.push.../../../../node_modules/@angular/core/fesm5
/core.js.ReflectiveInjector_._getByKey (core.js:2538)
at ReflectiveInjector_.push.../../../../node_modules/@angular/core/fesm5
/core.js.ReflectiveInjector_.get (core.js:2461)
at test (test.ts:40)
at Module../src/main.browser.ts (main.browser.ts:10)
at __webpack_require__ (bootstrap:78)
at checkDeferredModules (bootstrap:45)
at Array.webpackJsonpCallback [as push] (bootstrap:32)
at main.chunk.js:2
The only difference between the two class is that the parent class is in
another file.
I don't understand how this could have any impact on the resulting code.
Please note I'm using webpack to build with "ts-loader".
Thanks.
--
You received this message because you are subscribed to the Google Groups
"Angular and AngularJS discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.