角函数总是称为两次?
在Angular I中,我在NGFOR指令的阵列上迭代。 HTML模板中的功能趋势始终称为两次。 有什么原因?
html-file
<ul>
<li *ngFor="let exercise of exercises">
Name: {{exercise.name}}<br>
Sets: {{exercise.sets}}<span [innerHTML]="trend(exercise.sets,exercise.prev_sets)"></span>
</li>
</ul>
component.ts
trend(value: any, prev_value: any){
console.log("Result:" + value);
return "";
}
chrome console
Result: 12 exercises.component.ts:39
Result: 12 exercises.component.ts:39
in Angular I iterate over an array with the ngFor directive.
The function trend in the HTML Template is called always twice.
Is there any reason why?
HTML-FILE
<ul>
<li *ngFor="let exercise of exercises">
Name: {{exercise.name}}<br>
Sets: {{exercise.sets}}<span [innerHTML]="trend(exercise.sets,exercise.prev_sets)"></span>
</li>
</ul>
COMPONENT.TS
trend(value: any, prev_value: any){
console.log("Result:" + value);
return "";
}
CHROME CONSOLE
Result: 12 exercises.component.ts:39
Result: 12 exercises.component.ts:39
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在每个更改检测周期中调用来自模板的方法/函数调用,
以避免这种情况绑定到属性或创建自定义管道。您也可以使用
changeTectionstrategy.onpush
减少更改检测检查Method/function calls from the template are called on every change detection cycle
To avoid this either bind to a property or create a custom pipe. You can also use
ChangeDetectionStrategy.onPush
to reduce the change detection checks