I have an Angular app and an app.module.ts
file which contains two child modules.
Here is some reduced code:
// app.module.ts
@NgModule({
imports: [
AssetsModule,
SharedModule
]
The problem is that my AssetsModule
contains components that are used in the SharedModule
and my SharedModule
contains components that are used in my AssetsModule
.
I added the desired module to the imports
of the appropriate module file, like so (please note that my modules contain many components, I just have one here for readability)
// assets.module.ts
@NgModule({
declarations: [AssetsComponent],
imports: [
CommonModule,
SharedModule
],
exports: [AssetsComponent]
})
export class AssetsModule {}
// shared.module.ts
@NgModule({
declarations: [ChartComponent],
imports: [
CommonModule,
AssetsModule
],
exports: [ChartComponent]
})
export class SharedModule {}
Now the IDE gives me an issue and my application crashes in the browser.
Cyclic dependency between modules: SharedModule -> AssetsModule -> SharedModule Inspection info: Reports cyclic dependencies between Angular modules.
How do I resolve this error?
I could just have all components declared in the app.module.ts
but that isn't very elegant, modular and it may even be an anti-pattern. I don't want to combine the two modules into one as I will have other modules that will need to share components.