I need to get configuration from server before the application bootstraps. I was able to do that using this in providers in my main ngModule:
{
provide: APP_INITIALIZER,
useFactory: (links: Links) => () => links.init(),
deps: [Links, Http],
multi: true
}
Links service:
init(): Promise<any> {
var observable = this.http.get('someUrl').map(res => res.json());
observable.subscribe(res => {
this.config = res;
});
return observable.toPromise();
}
This code gets executed before the application bootstraps, but the response from server is not present until after my app asks for Links.config. How do I force the app to not bootstrap until after the Promise gets resolved? I tried promise.resolve(), but it didn't help.
The way I used providers I thought I forced the app to use the same instance of Links and also I thought the data would be already present there. What am I doing wrong please?