Currently I'm using a quite common solution to load a JSON file's content into my Angular 5 application that I can inject into my components. This works like it's described here under section Runtime configuration.
I'm using an npm package which needs to be initialized in my app.module.ts file
@NgModule({
declarations: [
AppComponent
],
imports: [
/* .... */
[MsalModule.forRoot({
clientID: "...",
authority: "...",
redirectUri: <I need the value here from the JSON file>
})]
],
providers: [
ConfigService,
{
provide: APP_INITIALIZER,
useFactory: (config: ConfigService) => () => config.load(),
deps: [ConfigService],
multi: true
}
]
bootstrap: [AppComponent]
})
export class AppModule { }
I use Angular-CLI and I know that I could use different environment files, but the content of the JSON file might change after building the application and I cannot rely on that.
Is there a way to use a value from the JSON file immediately in the NgModule declaration, where I need it?
A good alternative can be found here in this StackOverflow question
This way to JSON file can be loaded as a JS object and we can access it before declaring the NgModule.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With