How do I store my count value in locally in the ionic app?


#1

Hi guys I am working on this live project where I want to store the quantity/count values (1,2,3…) locally. I just need a little guidance with the code. I am learning ionic. This is my ts files code snippet.

this.cartArr.push(items);
        this.dataPrint = this.cartArr;
        let item =this.dataPrint;
        let selected = {};

            for(let obj of item){
            if(selected[obj.ITEMID]){
              selected[obj.ITEMID].count++;
            }else{
              selected[obj.ITEMID] = {...obj,count: 1};
            }
          }

      this.selectedItems = Object.keys(selected).map(key => selected[key])
      console.log('items: ',this.selectedItems);
      this.total = this.selectedItems.reduce((a, b) => a + (b.count * b.RATE), 0);
      this.storage.set('cartItems',this.selectedItems);

#2

Look at LocalStorage as a solution.


#3

Yes…But how do i just increment the count and display it in my html every timei increase my count by 1


#4

Stand template binding should work to reflect the value.