两者之间是否存在性能差异? 和 ?

问题描述 投票:0回答:1

我对<ng-container><ng-template>有疑问。哪个更适合在我们的代码中使用。我已经阅读了关于这两个标签在here上的差异的答案。它说Angular编译器通过转换去糖(使它有点复杂)

 `<div *ngFor="let person of persons"></div>`

对此

<ng-template ngFor let-person="$implicit" [ngForOf]="persons">
   <div>...</div>
 </ng-template>

所以我担心的是<ng-template>会影响浏览器中的渲染性能与<ng-container>相比,哪两个应该优先考虑?

angular angular2-template ng-template ng-container
1个回答
2
投票

如果您正在使用AoT编译,则根本没有任何区别,因为编译将会发生......提前完成。即使使用JiT编译,除非你渲染了数千个元素,否则你不应该真的担心它。

我想到的一些优化是:

© www.soinside.com 2019 - 2024. All rights reserved.