Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the implications of bootstrapping multiple components

Tags:

angular

I can do the following:

@NgModule({
    imports: [BrowserModule],
    declarations: [AppComponent, BComponent],
    bootstrap: [AppComponent, BComponent] <---------- here two components
})

and it'll create two html tags:

<my-app ng-version="2.4.5" _nghost-lii-0=""><h1 _ngcontent-lii-0="">Hello Angular</h1></my-app>
<b-app ng-version="2.4.5" _nghost-lii-0=""><h1 _ngcontent-lii-0="">Hello Angular</h1></b-app>

I'm wondering what are the implications of such setup? Am I just going to have two trees of components with a single injector or they will act as two different applications? Any other things I haven't thought about?

like image 248
Max Koretskyi Avatar asked Feb 03 '17 18:02

Max Koretskyi


1 Answers

Am I just going to have two trees of components with a single injector

Yes, you will have two independent root trees. They will be registered under ApplicationRef.views and when ApplicationRef.tick() function will be called Angular will run change detection for both trees. It will be single application and they will share the injector defined for the AppModule.

like image 162
Max Koretskyi Avatar answered Oct 21 '22 10:10

Max Koretskyi