• 개요
@angular/core

importProvidersFrom

함수
안정화

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

API

@paramsourcesImportProvidersSource[]
@returnsEnvironmentProviders

Collected providers from the specified list of types.

설명

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.

사용 시 참고사항

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
  }
];
상세 내용으로 이동