dawood abbas

dawood abbas

  • NA
  • 56
  • 4.8k

How to set a record on every click in localstorage and get?

Jul 16 2019 11:58 PM
I need to get all the lists when I storing the object records in local storage on every button clicks.
 
I tried like below, but on every click getting the same record which setting in present click, not getting previous clicks set records.
  1. $scope.AddToCart = function () { var items = [];  
  2. var listItems = { Garment: list.ItemName, Quantity: itemQty, Price: list.DryClean, Service: service, Total: totalPrice};  
  3. items.push(listItems); localStorage.setItem('listItems', JSON.stringify(items));  
  4. var stored = JSON.parse(localStorage.getItem("listItems")); c  
  5. onsole.log(stored);  
I would like to get like below
 
On first click :0: {Garment: "Thobe", Quantity: "1", Price: 5, Service: "", Total: 5}
 
On second click :
 
0: {Garment: "Thobe", Quantity: "1", Price: 5, Service: "", Total: 5}
1: {Garment: "Shirt", Quantity: "1", Price: 20, Service: "", Total: 25}
on third click :
0: {Garment: "Thobe", Quantity: "1", Price: 5, Service: "", Total: 5}
1: {Garment: "Shirt", Quantity: "1", Price: 20, Service: "", Total: 5}
2: {Garment: "Pant", Quantity: "1", Price: 30, Service: "", Total: 55}

Answers (1)