【发布时间】:2020-04-27 16:58:10
【问题描述】:
我有这个代码
TS
modal.onDidDismiss().then(res => {
if (res.data !== undefined) {
this.foodAllergies.push(res.data)
if (this.categories.length === 0) {
this.categories.push(res.data.category)
} else {
if (!this.categories.includes(res.data.category)) {
this.categories.push(res.data.category)
}
}
}
});
HTML
<ion-grid>
<ion-row *ngFor="let category of categories">
<ion-col>
<h3>{{category}}</h3>
<ion-list>
<ion-item *ngFor="let food of foodAllergies | categoryFilter: category">
<ion-label>{{food.name}}</ion-label>
</ion-item>
</ion-list>
</ion-col>
</ion-row>
</ion-grid>
因此,每当我向类别数组添加新类别时,视图都会正确更新,显示该类别中的食物 问题是,当我添加一个类别数组中已经存在的类别时,视图不会正确更新,因为第二个 ngFor 没有触发它不会添加具有该类别的食物
我该如何解决这个问题?
【问题讨论】:
标签: angular ionic-framework ionic4 ngfor