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

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

importProvidersFrom

function
stable

Collects providers from all NgModules and standalone components, including transitively imported ones.

On this page

    arrow_upward_alt Back to the top

    API

    @paramsourcesImportProvidersSource[]
    @returnsEnvironmentProviders

    Collected providers from the specified list of types.

    Description

    Collects providers from all NgModules and standalone components, including transitively imported ones.

    Providers extracted via importProvidersFrom are only usable in an application injector or another environment injector (such as a route injector). They should not be used in component providers.

    Usage Notes

    The results of the importProvidersFrom call can be used in the bootstrapApplication call:

    await bootstrapApplication(RootComponent, {
      providers: [
        importProvidersFrom(NgModuleOne, NgModuleTwo)
      ]
    });

    You can also use the importProvidersFrom results in the providers field of a route, when a standalone component is used:

    export const ROUTES: Route[] = [
      {
        path: 'foo',
        providers: [
          importProvidersFrom(NgModuleOne, NgModuleTwo)
        ],
        component: YourStandaloneComponent
      }
    ];
    Jump to details

    Web Proxy Viewer  |  New URL  |  Original Page