I have an Angular application based on Seed. I want it to wait for the loading of all data before displaying anything. That is done with a provider in my app.module.ts
:
providers: [
AlbumConfig,
UserConfig,
{
provide: APP_INITIALIZER,
useFactory: (config: AlbumConfig) => () => config.load(),
deps: [AlbumConfig],
multi: true
}
],
Problem is the config.load
(which eventually fires a resolve(true)
) needs an id given in the HTML page by the server:
<rmalbum-app data-id="<?php print $album_id; ?>">Loading...</rmalbum-app>
The only way I found to get this parameter is in the app.component
's constructor:
albumConfig.id= this.elementRef.nativeElement.getAttribute('data-id');
The problem is that this constructor is only called after the initialization.
So I either have, chronologically:
config.load()
- "Loading..." disappears
app.component
's constructor is called, I get the id, too late forconfig.load
or, if I remove the APP_INITIALIZER and put the config.load()
in the component's constructor:
- "Loading..." disappears
app.component
's constructor is called, I get the idconfig.load()
manually called from the constructor
I don't want that because it means the application is displayed before the config is actually loaded.