angular-di

Angular (v5) service is getting constructed before APP_INITIALIZER promise resolves

。_饼干妹妹 提交于 2020-05-25 09:35:44
问题 I'm expecting Angular to wait until my loadConfig() function resolves before constructing other services, but it is not. app.module.ts export function initializeConfig(config: AppConfig){ return () => config.loadConfig(); } @NgModule({ declarations: [...] providers: [ AppConfig, { provide: APP_INITIALIZER, useFactory: initializeConfig, deps: [AppConfig], multi: true } ] }) export class AppModule { } app.config.ts @Injectable() export class AppConfig { config: any; constructor( private

Angular (v5) service is getting constructed before APP_INITIALIZER promise resolves

你。 提交于 2020-05-25 09:34:30
问题 I'm expecting Angular to wait until my loadConfig() function resolves before constructing other services, but it is not. app.module.ts export function initializeConfig(config: AppConfig){ return () => config.loadConfig(); } @NgModule({ declarations: [...] providers: [ AppConfig, { provide: APP_INITIALIZER, useFactory: initializeConfig, deps: [AppConfig], multi: true } ] }) export class AppModule { } app.config.ts @Injectable() export class AppConfig { config: any; constructor( private

How to pass dependencies to @auth0-angular-jwt?

寵の児 提交于 2019-12-08 00:23:16
问题 So... I'm migrating my "old" code that was using the HttpModule and angular2-jwt lib. Before, I could make angular2-jwt work with the following config: export function authHttpServiceFactory( http: Http, options: RequestOptions, myService: MyService) { return new AuthHttp(new AuthConfig({ globalHeaders: [{'Content-Type': 'application/json'}], noJwtError: true, tokenGetter: (() => myService.get('my_token')) }), http, options); } @NgModule({ providers: [ { provide: AuthHttp, useFactory:

How to pass dependencies to @auth0-angular-jwt?

。_饼干妹妹 提交于 2019-12-06 08:51:19
So... I'm migrating my "old" code that was using the HttpModule and angular2-jwt lib. Before, I could make angular2-jwt work with the following config: export function authHttpServiceFactory( http: Http, options: RequestOptions, myService: MyService) { return new AuthHttp(new AuthConfig({ globalHeaders: [{'Content-Type': 'application/json'}], noJwtError: true, tokenGetter: (() => myService.get('my_token')) }), http, options); } @NgModule({ providers: [ { provide: AuthHttp, useFactory: authHttpServiceFactory, deps: [Http, RequestOptions, MyService] } ] }) export class AuthModule {} ... But now,

How to add another provider to the injector?

爱⌒轻易说出口 提交于 2019-12-04 14:33:31
问题 A framework-agnostic way of phrasing this question is "How to register another service with the service locator?" The Injector is set up to be immutable, both the interface and the implementation. interface Injector { abstract get(token: any, notFoundValue?: any): any; } interface https://github.com/angular/angular/blob/master/packages/core/src/di/injector.ts implementation https://github.com/angular/angular/blob/master/packages/core/src/di/reflective_injector.ts How do you add another

How to add another provider to the injector?

被刻印的时光 ゝ 提交于 2019-12-03 08:59:47
A framework-agnostic way of phrasing this question is "How to register another service with the service locator?" The Injector is set up to be immutable, both the interface and the implementation. interface Injector { abstract get(token: any, notFoundValue?: any): any; } interface https://github.com/angular/angular/blob/master/packages/core/src/di/injector.ts implementation https://github.com/angular/angular/blob/master/packages/core/src/di/reflective_injector.ts How do you add another provider (dynamically, not via a module)? How does Angular do this itself when it is loading new modules

Can I use custom ReflectiveInjector strategies to get component providers?

假装没事ソ 提交于 2019-11-29 15:03:55
As you all know we have different strategies for providers: useClass , useExisting , useFactory , useValue . But what if I would like to add own strategy? Something like: providers: [ { MyService: MyService, useAsyncFactory: MyAsyncFactory} ] What is the best way to extend ReflectiveInjector and make Angular use your extended variant? I found the place where it's defined, but still looking for a way to overwrite existing Angular DI mechanism. P.S.: Please don't ask why I need it and why not to use existing strategies. I'm doing research about Angular DI and the answer will help me to

Can I use custom ReflectiveInjector strategies to get component providers?

半世苍凉 提交于 2019-11-28 08:57:12
问题 As you all know we have different strategies for providers: useClass , useExisting , useFactory , useValue . But what if I would like to add own strategy? Something like: providers: [ { MyService: MyService, useAsyncFactory: MyAsyncFactory} ] What is the best way to extend ReflectiveInjector and make Angular use your extended variant? I found the place where it's defined, but still looking for a way to overwrite existing Angular DI mechanism. P.S.: Please don't ask why I need it and why not