I need to Store Cart Items to Native Storage and restore them into Cart Component
So , I use Native Storage offer by Ionic , i need to send item ( image , model-name ) into storage but in array of object not ( object ) and get them with getter function in array and display the array in the Cart Component
the problem is : how to define the value of key as array and set the array … and in second time to restore this array in get function
my code Setter :
public storeItem(): void {
this.nativeStorage.setItem('cart-items',
{
Model: this.Model,
Image: this.Image
})
.then(
() => console.log('Item successfuly saved!'+this.Model+this.Image),
error => console.error('Error storing item', error)
);
type or paste code here
and Getter function :
public getCartItems(): void {
this.nativeStorage.getItem('cart-items')
.then(
data => {
console.log("CART COMPONENT BEGIN...");
console.log(JSON.stringify(data));
this.StoredItems.push(JSON.stringify(data));
alert(JSON.stringify(data));
console.log("STOREDITEM"+this.StoredItems);
},
error => console.error(error)
);
}
1 post - 1 participant