在RC5之前,我正在使用像注射器这样的服务定位器:
Startup.ts
bootstrap(...) .then((appRef: any) => { ServiceLocator.injector = appRef.injector; });
ServiceLocator.ts
export class ServiceLocator { static injector: Injector; }
组件:
let myServiceInstance = <MyService>ServiceLocator.injector.get(MyService)
现在在bootstrapModule()中做同样的事情then()不起作用,因为组件似乎在承诺之前开始执行.
在组件加载之前有没有办法存储注入器实例?
我不想使用构造函数注入,因为我使用由许多组件导出的基本组件中的注入器,而不是将注入器注入到所有组件中.