【发布时间】:2018-11-28 09:01:43
【问题描述】:
我有一个简单的数组,里面有 6 个对象。 http://prntscr.com/jwp54d
我做了一个简单的*ngFor="",它应该并且确实显示了 6 行。
<ng-container *ngFor="let rec of deal.recycles">
<div *ngIf="checkReasonFilter(rec)" class="row" routerLink="/company" [queryParams]="{id: deal.withCompany}" fragment="recycled" >
我在checkReasonFilter(rec) 函数中添加了一个计数器,在加载时它被调用672 次strong>!
如何,为什么?有人知道吗?
函数只调用一次,在这里!
谢谢!
【问题讨论】:
-
*ngIf在渲染时不仅在每个更改检测循环中调用一次,因此您的函数在每次更改检测中被调用 6 次,因此总和 -
不鼓励在绑定中使用函数,您的函数将在每个更改检测周期被调用,并且在开发模式下 Angular 运行 x2 个周期。
标签: angular