Free tools Windows power users keep installed
One-click scans. No signup required.
APP_INITIALIZER is the dependency-injection token Angular uses to run functions during application startup, and Angular now recommends provideAppInitializer() in its place. If an initializer returns a Promise or an Observable, Angular holds initialization until the Promise resolves or the Observable completes. Angular’s API reference checked in October 2026 marks the token deprecated since v19.0.
What APP_INITIALIZER does
APP_INITIALIZER is a multi-provider token. You register one or more initializer functions under it, and Angular calls them while the application starts. Angular’s APP_INITIALIZER API reference describes the behavior this way: “The provided functions are injected at application startup and executed during app initialization.”
As an Amazon Associate I earn from qualifying purchases.
Two behaviors matter when you write one:
- Startup gating. A returned Promise must resolve, or a returned Observable must complete, before initialization finishes. Work you return is work the app waits for.
- Injection context. Initializers run in an injection context, so you can call
inject()inside the function to get dependencies.
The legacy pattern
In older code, the initializer is registered as a provider object with provide: APP_INITIALIZER and multi: true. A typical registration looks like this:
{
provide: APP_INITIALIZER,
useFactory: (config: ConfigService) => () => config.load(),
deps: [ConfigService],
multi: true,
}
The factory receives its dependencies through deps, and it returns the function Angular will execute at startup.
#1 Best Overall
Replacing it with provideAppInitializer
The current API is provideAppInitializer(initializerFn). It returns EnvironmentProviders and runs the supplied function at application startup. The same registration becomes:
provideAppInitializer(() => {
const config = inject(ConfigService);
return config.load();
})
Angular’s own example uses this shape to load configuration over HTTP before the app starts. It calls inject(HttpClient) inside the initializer and converts the request with firstValueFrom:
Rank #2
bootstrapApplication(App, {
providers: [
provideAppInitializer(() => {
const http = inject(HttpClient);
return firstValueFrom(http.get('/api/config'));
}),
provideHttpClient(),
],
});
Angular’s provideAppInitializer reference adds: “Note that the provided initializer is run in the injection context.”
Recommended Free Tools
Migration steps
- Search the project for
APP_INITIALIZERinprovidersarrays, NgModuleproviderslists, and test setups. - In an application bootstrapped with
bootstrapApplication, replace each{ provide: APP_INITIALIZER, ... }object with aprovideAppInitializer()call in the same providers array. - Move each entry from
depsinto aninject()call at the top of the function body. Remove thedepsarray and themultiflag. - Confirm the function returns a Promise that resolves, or an Observable that completes, when the startup work is finished.
- Start the app and check that the code that depended on the loaded data runs only after the initializer finishes.
NgModule applications can keep the legacy token. Angular’s documentation presents it as a legacy pattern and does not require moving to standalone bootstrapping to adopt provideAppInitializer.
Rank #3
Async behavior: Promises and Observables
Angular accepts a Promise or an Observable from an application initializer and waits on either one. For a Promise, the wait ends when it resolves. For an Observable, the wait ends when the stream completes, not when it emits its first value.
This has a practical consequence. An Observable that never completes keeps initialization pending. This follows from the documented completion rule rather than from a separate example in Angular’s reference, so design the stream to complete once the required work is done. Use firstValueFrom or lastValueFrom when you want a one-shot request, or add take(1) to a long-lived stream.
Rank #4
Three initializer APIs and their scopes
The names are similar, but each API runs at a different point in the lifecycle. Pick the one that matches when your code needs to run.
| Lifecycle scope | Provider function | Legacy token | Function signature and async contract | Provider form |
|---|---|---|---|---|
| Application startup | provideAppInitializer |
APP_INITIALIZER (deprecated since v19.0) |
Can return a Promise or Observable; Angular waits for resolution or completion | EnvironmentProviders |
| Platform injector setup | providePlatformInitializer |
Legacy platform initializer token | Documented as () => void; no async wait |
StaticProvider |
| Environment injector construction | provideEnvironmentInitializer |
ENVIRONMENT_INITIALIZER (deprecated since v19.0) |
Documented as () => void; no async wait |
EnvironmentProviders |
Use providePlatformInitializer and provideEnvironmentInitializer only when your code must run at those lower-level points. Neither is a drop-in substitute for application startup work that needs to be awaited.
Deprecation timing
The APP_INITIALIZER reference marks the token deprecated since v19.0 but does not name a removal release. Angular’s versioning and releases policy says deprecated APIs remain available through at least the next major release and may be removed after that deprecation period. Check the release notes for the Angular version you deploy before planning a removal date, because the policy describes a window rather than a fixed version.
For new code, use provideAppInitializer now. For existing NgModule code that works, there is no urgency to rewrite it on the strength of the deprecation alone.
Quick Recap
Checklist before you ship
- Every initializer returns a Promise that resolves or an Observable that completes.
- No initializer depends on a value that a later initializer is supposed to provide, since the order of your startup work should be explicit.
- Dependencies are obtained with
inject()inside the function, not captured from outside it. - Platform and environment initializers are used only where the lifecycle requires them.
“
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




