Cookies concent notice

This site uses cookies from Google to deliver its services and to analyze traffic.
Learn more
Skip to main content
This site is no longer updated.Head to Angular.devHome
/

This is the archived documentation for Angular v17. Please visit angular.dev to see this page for the current version of Angular.

importProvidersFrom

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

See more...

      
      importProvidersFrom(...sources: ImportProvidersSource[]): EnvironmentProviders
    
Parameters
sources ImportProvidersSource[]
Returns

EnvironmentProviders: Collected providers from the specified list of types.

Description

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.

More information about standalone components can be found in this guide.

Further information is available in the Usage Notes...

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
  }
];