I wants to reuse a directive in multiple modules. I can“t declare the directive in parentmodule because all childmodules are loaded by lazy loading. If i declare the same directive in both childmodules i get an error:
ERROR Error: Uncaught (in promise): Error: Type AddDirective is part of the declarations of 2 modules: SharedModule and GdprModule! Please consider moving AddDirective to a higher module that imports SharedModule and GdprModule. You can also create a new NgModule that exports and includes AddDirective then import that NgModule in SharedModule and GdprModule.
AddDirective is a simple directive which provide me ViewContainerRef which i need for dynamical components. I add them by following tutorial:
https://angular.io/guide/dynamic-component-loader
Do i have to create a own directive for every lazy module or is there any way to provide the same directive by shared module for example?
SharedModule:
@NgModule({
imports: [
CommonModule
],
declarations: [
AddDirective
]
})
LazyModule:
import { SharedModule } from './pathToShared/sharaed.module';
@NgModule({
imports: [ SharedModule ],
declarations: [ LazyComponent],
entryComponents: [ DynamicalComponent ]
})
export class LazyModule { }