I have the following plunker
This is the part to pay special attention:
export function startupServiceFactory(startupService: StartupService): Promise<any> {
console.log('on startupService', startupService); // (1)
return () => {
console.log("on return service load()"); // (2)
return startupService.load()
};
}
You will be able to see in the console that even when the first console.log
(1) call comes prior to the one from the module's constructor, the next one right below the return () =>
doesn't (2).
I need to get a certain configuration from the server so then I can initialize a service from the module's constructor with that same data. Am I missing something or is this just not possible? How can I make a call to the server before anything else in an Angular app?
EDIT: By comment request, I'll try to explain a bit better: I'd need to postpone the execution of the module constructor so I can get certain configuration from the server prior to continue the execution of the application.
Please, don't mistake this question with this or this, as these don't deal with how to make the load occur before the module's constructor execution, they just explain the basic use of APP_INITIALIZER
token.