How can I import a module into standalone directive
Asked Answered
P

1

7

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 ?

Phago answered 14/2, 2023 at 8:8 Comment(4)
There doesn't seem to be a way to do that if you refer to angular.io/api/core/Directive Although I don't really see a use case where you need to import modulesDelrosario
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.Oxpecker
There are plenty of use cases when considering Angular Material modules.Phago
Do you have a specific usecase to show us a example what you need?Oxpecker
P
2

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)
  ]
});
Phago answered 14/2, 2023 at 10:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.