Quantcast
Channel: Ionic Framework - Ionic Forum
Viewing all articles
Browse latest Browse all 48983

How to use Native Storage to Add to Cart functionnality?

$
0
0

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

Read full topic


Viewing all articles
Browse latest Browse all 48983

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>