Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more

ENVIRONMENT_INITIALIZER is deprecated in Angular 19 and later. For a synchronous callback that should run when an environment injector is constructed, use provideEnvironmentInitializer. For application-startup work that must wait for a Promise or Observable, use provideAppInitializer. Choose by lifecycle scope; these APIs are not interchangeable.

What ENVIRONMENT_INITIALIZER does

ENVIRONMENT_INITIALIZER is an Angular injection token for callbacks run when an environment injector is constructed. Its current API reference marks it deprecated since Angular v19.0 and recommends provideEnvironmentInitializer instead. Angular’s API reference

An environment injector can be created outside the application’s main startup flow. Use this initializer for setup that belongs to that injector’s construction, rather than assuming it will hold application bootstrap until asynchronous work finishes.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Replace it with provideEnvironmentInitializer

Pass the callback to provideEnvironmentInitializer in the provider list for the environment injector. Angular runs the callback in an injection context, so dependencies can be injected there.

import { createEnvironmentInjector, provideEnvironmentInitializer } from '@angular/core';

const environmentInjector = createEnvironmentInjector(
  [
    provideEnvironmentInitializer(() => {
      // Synchronous setup for this environment injector
    }),
  ],
  parentInjector,
);

The documented callback signature is () => void. Angular’s reference describes the function as providing initialization callbacks executed upon construction of an environment injector. provideEnvironmentInitializer API reference

Choose the initializer by lifecycle

Need API Behavior
Synchronous setup when an environment injector is constructed provideEnvironmentInitializer Returns EnvironmentProviders; callback runs in an injection context.
Application startup work that must wait for asynchronous completion provideAppInitializer If the callback returns a Promise or Observable, Angular waits for it to resolve or complete before finishing application initialization.
Setup when the platform injector is initialized providePlatformInitializer Platform-level initializer provided during platform creation.

Angular documents the app initializer’s Promise and Observable waiting behavior separately from the environment initializer’s synchronous callback signature. Select the API for the injector lifecycle the work belongs to. provideAppInitializer API reference providePlatformInitializer API reference

Legacy providers and NG0209

If you still need the deprecated token in existing code, it is a multi-provider token. Its legacy provider must include multi: true:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
{
  provide: ENVIRONMENT_INITIALIZER,
  multi: true,
  useValue: () => {
    // Synchronous environment-injector setup
  },
}

Omitting multi: true for a token intended for multiple providers can cause Angular’s NG0209 invalid multi provider error. Prefer provideEnvironmentInitializer in new code. Angular NG0209 guide

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

What the deprecation means for removal

Angular labels the token deprecated since v19.0. Its release policy says deprecated APIs remain available through at least the next major release and may be removed only in a later major release. The token’s API reference does not name a removal version, so no specific removal release can be inferred. Token API reference Angular deprecation policy

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.