【问题标题】:Using trackBy with ngFor in angular 6 improve performance?在 Angular 6 中使用 trackBy 和 ngFor 可以提高性能?
【发布时间】:2019-02-05 17:55:27
【问题描述】:

在 Angular 6 中将 trackBy 与 ngFor 结合使用可提高性能

 <app-analysis-item *ngFor="let element of analyses"
                     [analysis]="element"

     (deleteAnalysisEvent)="onAnalysisDeleted($event)">  
</app-analysis-item>


        If yes why angular team don't say that ????.

【问题讨论】:

标签: angular performance ngfor


【解决方案1】:

是的,它通过在 for 循环中使用 trackBy 来提高性能,

如果你知道 React 或其他技术中的 Virtual DOM 的概念,trackBy 和 ngFor 的工作原理就是这样

另外,很多博主都提到了这一点: helpful link

【讨论】:

    【解决方案2】:

    这里我们将使用 TrackBy 和 *ngFor 来提高 Web 应用程序的性能, 为什么,因为当数据加载到数据表中时。如果任何新记录被添加到该现有对象,Dom 将再次呈现总页, 为了克服这个问题,我们使用了 TrackBy,而当我们在不重新渲染的情况下将新项目添加到现有对象时,它会将新项目添加到现有列表中。

    【讨论】:

      猜你喜欢
      • 2018-09-27
      • 2019-03-20
      • 2017-06-25
      • 2020-01-15
      • 2020-10-25
      • 1970-01-01
      • 2018-07-03
      • 2017-04-19
      • 2019-11-19
      相关资源
      最近更新 更多