I've been trying to use the APP_INITIALIZER
during the bootstrap process to load some configuration data (similar to How to pass parameters rendered from backend to angular2 bootstrap method, Angular2 APP_INITIALIZER not consistent, and others).
The problem I'm facing is that I need to make 2 requests, the first one to a local json file where a URL resides, then the request to that URL to get the actual configuration.
For some reason however the startup is not delayed until the promise resolves.
This is the load method that gets called via the APP_INITIALIZER
public load(): Promise<any>
{
console.log('bootstrap loading called');
const promise = this.http.get('./src/config.json').map((res) => res.json()).toPromise();
promise.then(config => {
let url = config['URL'];
console.log("loading external config from: ./src/" + url);
this.http.get('./src/' + url).map(r => r.json()).subscribe(r => { this.config = r; console.dir(r);});
});
return promise;
}
And here is a complete plnkr demonstrating the problem (check the console output).
Obviously I'm missing an important understanding of the concept.
How can I get the app to wait for both requests to return before the component is loaded?