'How to give configuration file that angular lib received from app to libs imported another module?
This is my code I want to use config that i receive from app. But now i can use config only when i inject service somewhere but cant give it to my factory. My apps angular version is 12 and lib is 11. In my config there is ApiUrl that libs MSALServiceFactory must do a call and receive a parameters to start working.
export function MSALInstanceFactory(): IPublicClientApplication {
// need to use config here
}
export function MSALServiceFactory(location: Location): MsalService {
return new MsalService(MSALInstanceFactory(), location);
}
@NgModule({
declarations: [MyLIbComponent],
imports: [
HttpClientModule,
CommonModule,
FormsModule,
MsalModule,
],
providers: [
JwtHelperService,
{
provide: 'MsalService-token',
useFactory: MSALServiceFactory,
deps: [Location]
},
{ provide: JWT_OPTIONS, useValue: null }
],
exports: [MyLIbComponent]
})
export class MyLibModule {
static forRoot(config: IConfig): ModuleWithProviders<MyLibModule> {
return {
ngModule: MyLibModule,
providers: [
config.authService,
config.languageService,
{ provide: MyLibConfigService, useValue: config },
]
};
}
static forChild(): MyLibModule {
return MyLibModule ;
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
