【发布时间】:2020-05-05 00:24:09
【问题描述】:
我目前有以下html代码:
<ng-container *ngFor="let goal of goalList;>
<tab>
<h3 class="...">{{goal?.title}}</h3>
<p class="...">{{goal?.description}}</p>
</tab>
</ng-container>
我需要有空的“目标”对象,以便选项卡的 ngFor 起作用。所以在组件中我像这样初始化goalList数组:this.goalList = Array(goalCount) // as I know the count already。
稍后,一旦请求,我将使用 Observable 从后端加载goalList,并用服务器的结果替换“空”数组:
this.serviceExample.goalListObservable.subscribe(
data => this.goalList = data
));
不幸的是,当前值会消失,因为后面的数组会被覆盖。
是否可以更改组件中的数组以使 Ui 中的值自动刷新?
【问题讨论】:
标签: angular typescript