Before RC5 I was using appref injector as a service locator like this:
Startup.ts
bootstrap(...)
.then((appRef: any) => {
ServiceLocator.injector = appRef.injector;
});
ServiceLocator.ts
export class ServiceLocator {
static injector: Injector;
}
components:
let myServiceInstance = <MyService>ServiceLocator.injector.get(MyService)
Now doing the same in bootstrapModule().then() doesn't work because components seems to start to execute before the promise.
Is there a way to store the injector instance before components load?
I don't want to use constructor injection because I'm using the injector in a base component which derived by many components and I rather not inject the injector to all of them.
bootstrap: [AppComponent]
and not usingngDoBootstrap
? Or is there a chance that AppModule's constructor could be called after bootstraping? – Piggyback