Bootstrapping multiple modules in angular?

1.1K    Asked by Aryangupta in Python , Asked on Dec 19, 2019
Answered by Aryan gupta

We can customize the bootstrapping via implementing ngDoBootstrap as a method of AppModule. You can list your components which need to be bootstrapped in the entryComponents property of @NgModule

@NgModule({

  entryComponents: [AComponent, BComponent, ...]

  ...

})

export class AppModule {

   constructor() {}

ngDoBootstrap(app: ApplicationRef) {

   if (Math.random() > 0.5) {

       appRef.bootstrap(AComponent, '#app');

   } else {

       appRef.bootstrap(BComponent, '#app');

   }

}

If we need a service, you can access them via dependency injection (put it in AppModule as constructor parameter). But I don't know if there are any limitations to it compared to DI in components or services.



Your Answer

Interviews

Parent Categories