4

The imports attribute is available on the @Component decorator but not on the @Directive decorator.

Is there another way to import a module into a standalone directive ?

Matthieu Riegler
  • 31,918
  • 20
  • 95
  • 134
  • There doesn't seem to be a way to do that if you refer to https://angular.io/api/core/Directive Although I don't really see a use case where you need to import modules – PasNinii Feb 14 '23 at 08:24
  • One (bad) case is to use httpClientModule. But you should not use something in directives. Use Interceptors, Guards, or Services for all things a module is needed. It's the better approach. – Flo Feb 14 '23 at 08:45
  • 3
    There are plenty of use cases when considering Angular Material modules. – Matthieu Riegler Feb 14 '23 at 08:50
  • 1
    Do you have a specific usecase to show us a example what you need? – Flo Feb 14 '23 at 09:08

1 Answers1

1

The current alternative is to provide them at the root of the application with importProvidersFrom (or in the router config).

await bootstrapApplication(RootComponent, {
  providers: [
    importProvidersFrom(NgModuleOne, NgModuleTwo)
  ]
});
Matthieu Riegler
  • 31,918
  • 20
  • 95
  • 134