provideAppInitializer
The provided function is injected at application startup and executed during app initialization. If the function returns a Promise or an Observable, initialization does not complete until the Promise is resolved or the Observable is completed.
function provideAppInitializer( initializerFn: () => void | Observable<unknown> | Promise<unknown>): EnvironmentProviders;
provideAppInitializer
The provided function is injected at application startup and executed during app initialization. If the function returns a Promise or an Observable, initialization does not complete until the Promise is resolved or the Observable is completed.
You can, for example, create a function that loads language data
or an external configuration, and provide that function using provideAppInitializer()
.
The function is executed during the application bootstrap process,
and the needed data is available on startup.
Note that the provided initializer is run in the injection context.
Previously, this was achieved using the APP_INITIALIZER
token which is now deprecated.
() => void | Observable<unknown> | Promise<unknown>
EnvironmentProviders