My scenario involves a dynamic array
filled with items and values. The goal is to remove an item from the view list when a user clicks a button on that particular item. I'm struggling to identify why this functionality isn't working as expected. Could it be due to how the data is structured? Despite seeing it being removed in the console, the issue persists. Any insights would be greatly appreciated. Thank you!
TS:
export class Page{
items: Item[];
constructor(public alertCtrl: AlertController){}
removeitem(i) {
let confirm = this.alertCtrl.create({
title: 'Confirm',
message: "text.",
buttons: [
{
text: 'Cancel',
handler: () => {
console.log('Disagree clicked');
}
},
{
text: 'Save',
handler: () => {
this.presentToast()
this.items.splice(i, 1);
}
}
]
});
confirm.present();
}
getItems(){
this.stopService.getItems().subscribe(item => {
this.items = item
})
}
}
HTML:
<div *ngFor="let item of items; index as i ">
<h3>{{item.description}}</h3>
<button item-end ion-button full (click)="removeitem(i)">remove item</button>
</div>
EDIT
Here's how I retrieve items using a service --
getItems(): Observable<any> {
return this.http.get(someEndpoint)
.map(res => res.json());
}