我是我的 angular 5 组件的 HTML 文件,我已经将*ngIf
附加到td
元素:
<tr *ngFor="let ar of ars">
<td *ngIf="showCompleteButton(ar)">
我遇到的问题是showCompleteButton
访问可能尚未从网络加载的元素。 当我需要的网络元素加载时,如何告诉页面重新运行该检查以使按钮开始出现?
我知道如何从网络调用.subscribe()
以在加载完成后采取行动,我只是不知道如何在那时重新评估该*ngIf
调用。
在模板中填写订阅的成员变量对您有用吗?如ts
:
showCompleteButton = {};
yourApiCall.subscribe(ars => {
this.ars = ars;
ars.forEach(ar => {
this.showCompleteButton[ar] = this.showCompleteButton(ar);
//do not know what type ar is but you get the idea...
});
在 HTML 中:
<td *ngIf="showCompleteButton[ar]">
旁注:从模板调用函数不利于性能,它将在每个周期中一遍又一遍地调用。