0

How do I properly set up a child module within the shared module of the application without getting circular dependency warnings or is it bad practice to have modules within modules?

I have a shared module containing shared functionality across the application. Within that shared module I have a module that needs to access the pipes in the shared module. In my example below the SchedulerModule needs to access the DigitToHourPipe which is declared in the SharedModule.

@NgModule({
  declarations: [DigitToHourPipe],
  imports: [CommonModule, AngularSplitModule],
  exports: [SchedulerModule, DigitToHourPipe]
})
export class SharedModule {}

@NgModule({
  declarations: [
    SchedulerComponent,
    EventViewComponent,
    EmployeeViewComponent,
    EventComponent
  ],
  imports: [CommonModule, AngularSplitModule.forRoot(), MatTableModule],
  exports: [SchedulerComponent]
})
export class SchedulerModule {}

Am I being stupid for having modules within modules or am I just doing something else wrong?

Tjulu
  • 79
  • 1
  • 9
  • 3
    I think you shouldn't export the SchedulerModule in the SharedModule, but import the SharedModule in your SchedulerModule – Benedikt Aug 29 '19 at 18:42
  • Well that made it to work, but now that Module isn't a part of the shared module. Perhaps that's impossible to achieve? – Tjulu Aug 29 '19 at 19:29
  • 1
    The name SharedModule somehow indicates it is used by other modules. Therefore, it is not possible without circular dependencies. – Benedikt Aug 29 '19 at 20:17

0 Answers0