Skip to content

module structure

Raphaël Balet edited this page Mar 27, 2025 · 4 revisions

my.module.ts

Example on how the module.ts should be structured.

export function myFactory(_myService: MyService) {
  return async () => await _myService.init()
}

@NgModule({
  imports: [
    CommonModule, // <-- CommunModule, NgIf, NgFor, ... does not need any comments

   // Shared
   SharedModule, // <-- Barrel import : Do not overuse

   // Components <-- Alphabetical order
   ComponentModule,
   StandaloneComponent,

   // Fragments

   // Layouts

   // Modals

   // Pipes

   // Services

   // Vendors
  ],
  exports: [
  ],
  providers: [
    { provide: VARIABLE, useValue: `Johndo` },
    {
      provide: APP_INITIALIZER,
      useFactory: myFactory,
      deps: [MyService],
      multi: true,
    },
    AnyService,
    {
      provide: BaseService,
      useExisting: AnyService,
    },
  ],
})

Clone this wiki locally