自举多个组件的含义是什么 [英] What are the implications of bootstrapping multiple components
问题描述
我可以执行以下操作:
@NgModule({
imports: [BrowserModule],
declarations: [AppComponent, BComponent],
bootstrap: [AppComponent, BComponent] <---------- here two components
})
,它将创建两个html标签:
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?
推荐答案
我只用一个注射器就拥有两棵树
Am I just going to have two trees of components with a single injector
是的,您将有两个独立根树.它们将在ApplicationRef.views
下注册,并且在调用ApplicationRef.tick()
函数时,Angular将同时对这两个树进行更改检测.这将是单个应用程序,它们将共享为AppModule
定义的进样器.
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
.
这篇关于自举多个组件的含义是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!