I am using ionic 3 with storage.
First, i import storage in the app.module.ts
import { IonicStorageModule } from '@ionic/storage';
imports: [
IonicStorageModule.forRoot()
]
I developed Ecommerce app.If I add to any product to cart using storage.
this.items.push(item);
this.storage.set('products',this.items);
item is a product detail.and I have displayed the cart count.
this.storage.get('products').then((data) => {
if(data != null)
{
this.Cartproducts=data;
console.log(this.Cartproducts);
}
});
here is my consoled value.
[
{
'Product_title':'Product name',
'Product desc':'product dec',
'id':1
},
{
'Product_title':'Product name',
'Product desc':'product dec'
'id':2
}
]
If i need remove the last product.
this.Cartproducts.splice(i, 1);
console.log(this.Cartproducts);
this.storage.remove('products');
this.storage.set('products',this.Cartproducts);
Here is my consoled value.
[
{
'Product_title':'Product name',
'Product desc':'product dec',
'id':1
}
]
I remove the storage value in ‘products’ Again I set the value products
I I need another product.so I am going to the product page and add the product.
But my result is
[
{
'Product_title':'Product name',
'Product desc':'product dec',
'id':1
},
{
'Product_title':'Product name',
'Product desc':'product dec'
'id':2
},
{
'Product_title':'Product name',
'Product desc':'product dec'
'id':3
}
]
But Actually, I remove the second product.Did not set to storage why?
Kindly advice me,
Thanks