Html DOM中可以有多少个模板元素?

Html DOM中可以有多少个模板元素?,html,angular,Html,Angular,我刚刚开始学习angular2,他们如何使用*ngFor,*ngIf实现模板的概念/架构,以及定义我自己的元素对我来说都是新概念 但是我想知道的是(因为文档中没有提到),定义大量模板是否会影响性能 比如, <div *ngFor="let screen of screens" [ngSwitch]="screen.templateID"> <!-- huge loop --> <template [ngSwitchCase]="0">{{screen.id

我刚刚开始学习angular2,他们如何使用
*ngFor
*ngIf
实现模板的概念/架构,以及定义我自己的
元素对我来说都是新概念

但是我想知道的是(因为文档中没有提到),定义大量模板是否会影响性能

比如,

<div *ngFor="let screen of screens" [ngSwitch]="screen.templateID"> <!-- huge loop -->
  <template [ngSwitchCase]="0">{{screen.id}} | {{screen.templateURL}}</template>
  <template [ngSwitchCase]="1">{{screen.id}} | {{screen.templateURL}}</template>
  <template [ngSwitchCase]="1">{{screen.id}} | {{screen.templateURL}}</template>
</div>

{{screen.id}}{{screen.templateURL}}
{{screen.id}}{{screen.templateURL}}
{{screen.id}}{{screen.templateURL}}

假设它可以生成数千个模板,生成这么多模板是“可以接受的”,还是我应该添加更多的逻辑来减少实例化的数量?

我想你需要自己做基准测试。我看不出有什么明显的原因会成为问题<代码>元素在构建时由Angular2处理,在以某种方式(NgfortTemplate、createdEmbeddedView、ngSwitchCase等)标记之前,不会添加到DOM中。“我是否应该添加更多逻辑以减少实例化的数量”我认为这不能一般地回答。有趣的是,谢谢@GünterZöchbauer-我最终使用了路由,这完全缓解了这个问题。当我引起你的注意时,你能看看我关于Angular2的另一篇文章吗?当我研究这个问题时,你对github问题在这个主题上的归因是非常深刻的,所以祈祷吧,你会很容易看到是什么导致了我的戏剧。谢谢你抽出时间。