我想要做的是删除元素后刷新Ionic 4列表项,因为我收到以下错误:
的HTML:
<ion-list [hidden]="showAllStations==false">
<ion-item *ngFor="let item of wayPoints; let i = index">
<ion-label>{{item.location}}</ion-label>
<ion-checkbox slot="start"
(ionChange)="delete(i)"></ion-checkbox>
</ion-item>
<ion-button type="submit" (click)="deletStations()" expand="block" class="ion-text-center ion-margin-top" >Valide</ion-button>
</ion-list>
ts:
delete(index){
console.log(index);
this.deletedStations.push(index);
// delete this.wayPoints[index];
console.log(this.deletedStations);
}
deletStations(){
this.deletedStations.forEach(index => delete this.wayPoints[index]);
console.log(this.wayPoints);
this.modalCtrl.dismiss(this.wayPoints);
}
错误:
ERROR TypeError: Cannot read property 'location' of undefined
尝试这个 :
delete(index){
this.wayPoints.splice(index, 1);
}
您只需使用上述方法从数组中删除该项目,您的数组就会自动更新,更改将反映在列表的前端,在这种情况下,您无需手动刷新列表。祝好运 :)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句