[ Web Proxy ]
URL:
Viewing: https://angular.dev/api/core/provideEnvironmentInitializer [Back]  [Original]

provideEnvironmentInitializer Angular Skip to main content
menu
close
more_horiz
menuAPI
@angular/core

provideEnvironmentInitializer

function
stable

This function is used to provide initialization functions that will be executed upon construction of an environment injector.

ENVIRONMENT_INITIALIZER

On this page

    arrow_upward_alt Back to the top

    API

    function provideEnvironmentInitializer(
      initializerFn: () => void,
    ): EnvironmentProviders;
    @paraminitializerFn() => void

    Description

    This function is used to provide initialization functions that will be executed upon construction of an environment injector.

    Note that the provided initializer is run in the injection context.

    Previously, this was achieved using the ENVIRONMENT_INITIALIZER token which is now deprecated.

    Usage Notes

    The following example illustrates how to configure an initialization function using provideEnvironmentInitializer()

    createEnvironmentInjector(
      [
        provideEnvironmentInitializer(() => {
          console.log('environment initialized');
        }),
      ],
      parentInjector
    );
    Jump to details

    Web Proxy Viewer  |  New URL  |  Original Page