I would like to import a module in my project with a certain configuration loaded from a file, that configuration file could be modified at runtime and the application should be loaded with the new changes when the browser is refreshed.
What I am doing now is to send the configuration file path to the module in the "forRoot" method and providing the configuration with the "useFactory" that points to a "load" method, this "load" method is just using an HTTP GET to retrieve my configuration file. Everything seems to be working fine with "ng build" until I execute "ng build --prod --build-optimizer", that is causing an "Error encountered resolving symbol values statically".
I suppose its cause is because I am using a provider with "useFactory" inside static "forRoot" method and that "useFactory" is pointing to a non-static method. How is it possible to deal with this? is this a good approach?
This is how my 'forRoot' method and 'initConfig' method looks like:
export class JwtSecurityModule {
public static forRoot(configPath:string) {
return {
ngModule: JwtSecurityModule,
providers: [
AppConfig,
{
provide: APP_INITIALIZER,
useFactory: initConfig,
deps: [AppConfig, configPath],
multi: true
}
]
};
}
...
}
...
export function initConfig(config:AppConfig, configPath: string) {
return () => config.load(configPath);
}