Hello guys,
I’m using Ionic storage. I have two pages. The first page is for saving items to favorite list.
The second page is a list of favorite items which has delete function.
I added several items using this command on the first page.
this.storage.set(
item ${ this.item.id }, this.item;
The first page is linked to dataProvider. This saves item with key: item {{ item’s id number ]} to SQlite storage along with all of its attributes from dataProvider.
On the second page, I’m fetching all saved items from storage to a list using below command:
ionViewDidLoad() {
this.storage.forEach( (item) => {
this.storageItems.push(item);
})
}
and this can fetch all items from storage with *ngFor directive and {{ item.name }}, {{ item.description }}
I’m trying to delete the item using: this.storage.remove(
item ${ this.item.id });
However it throws me an error:
Cannot read property 'id' of undefined
How can I work around this? this delete command works well on the first page which has imported dataProvider.
The second page is fetching items using interface and storage.
export interface StorageItem {
name: string,
description: string,
id: nubmer;
}
I’m using *ngFor="let item of StorageItems"
on second page.
this.storageItems.splice(index, 1);
didn’t work… I’ve tried this.storageItems.pop()
as well. None of them can erase an item from favorite list although items can be erased from the first page which received item’s attributes directly from the dataProvider.
What am I missing here?
Any help would be appreciated!
Thanks in advance