【发布时间】:2019-09-08 08:43:26
【问题描述】:
当我在 angular 中使用 *ngFor 和返回数据的函数时,该函数会被多次调用,有时甚至会导致循环:
app.component.ts
export class AppComponent {
getArray(): string[] {
//here i know when this function is called
console.log('getArray called')
return ['number one', 'number two']
}
}
app.component.html
<h1 *ngFor="let item of getArray()">
{{ item }}
</h1>
我的控制台:
然后我得到函数 getArray() 被多次调用,我不知道为什么。
【问题讨论】:
-
在我的 app.component.html 中,第一行。
标签: angular typescript ngfor templatebinding