When we bootstrap an angular application, which component should angular runtime start? or which component is root component. Here is the way:
Option 1: NgModule.bootstrap attribute
This is the most used option, @angular/cli default generated, in angular guides and examples:
@NgModule({
declarations: [
AppComponent,
],
imports: [
BrowserModule,
],
providers: [ ],
bootstrap: [AppComponent],
})
export class AppModule implements DoBootstrap {
}
Option 2: implement DoBootstrap
interface
@NgModule({
...
entryComponents: [AppComponent],
})
export class AppModule implements DoBootstrap {
ngDoBootstrap(appRef: ApplicationRef): void {
appRef.bootstrap(AppComponent);
}
}
Maybe angular compiler generate the appRef.bootstrap()
call somewhere.
网友评论