Skip to content

main structure

Raphaël Balet edited this page Mar 27, 2025 · 1 revision

main.ts

Example on how the main.ts should be structured

if (environment.production) {
  enableProdMode()
}

export function initApp(
  fooService: FooService,
) {
  return async () => {
    await firstValueFrom(
      fooService.initialized$.pipe(
        filter((event) => (event ? true : false)),
        take(1),
      ),
    )
  }
}

bootstrapApplication(AppComponent, {
  providers: [
    { provide: VARIABLE, useValue: `Johndo` },
  
    provideAnimationsAsync(),
    provideAppInitializer(async () => {
      const fooService = inject(FooService)

      await initApp(
        fooService
      )()
    }),

    importProvidersFrom(
      FooModule.forRoot()
    ),

    provideHttpClient(
      withInterceptors([fooInterceptorFn]),
    ),

    {
      provide: DateAdapter,
      useClass: FoorDateAdapter,
    },
  ],
})

Clone this wiki locally