My query involves modifying the config file on pageload based on a URL parameter. I currently have implemented the following:
config-loader.service.ts
@Injectable()
export class ConfigLoaderService {
constructor(private injector: Injector, private http?: HttpClient) { }
public get router(): Router {
return this.injector.get(Router);
}
url : string;
link : string;
initialize() {
this.url = this.router.url;
if (this.url == "/demo")
{
this.link = 'assets/demoConfig.json'
}
else {
this.link = 'assets/config.json'
}
return this.http.get<ModeActivation>(this.link)
.pipe(tap((response: ModeActivation) => {
app.module.ts
providers: [DemandeClass,
ConfigLoaderService,
{
provide: APP_INITIALIZER,
deps: [
ConfigLoaderService
],
multi: true,
useFactory: PreloadFactory
}
],
Although I am not encountering any errors, the
this.router.url
is always "/" even when I access
localhost:4200/demo
leading to it entering the second condition. Can anyone pinpoint what could be going wrong?