Skip to main content
added 28 characters in body
Source Link
Pawan Nogariya
  • 9k
  • 14
  • 61
  • 137

Yes because you are not adding items to your $localStorage.items and cart variables but every timeyou are assigning them completely new values to it every time and so it lost the last added values. You are re-initializing them everytimeevery time and so they loose last added values.

You should do something like this

if ($scope.cart != 0) { // instead of this //$localStorage.items = $scope.cart; // you should do this for(var i=0; i<$scope.cart.length; i++) { $localStorage.items.push($scope.cart[i]); } } 

Yes because you are not adding items to your items and cart variables but every time assigning them completely new values. You are re-initializing them everytime and so they loose last added values.

You should do something like this

if ($scope.cart != 0) { // instead of this //$localStorage.items = $scope.cart; // you should do this for(var i=0; i<$scope.cart.length; i++) { $localStorage.items.push($scope.cart[i]); } } 

Yes because you are not adding items to your $localStorage.items but you are assigning new values to it every time and so it lost the last added values. You are re-initializing them every time and so they loose last added values.

You should do something like this

if ($scope.cart != 0) { // instead of this //$localStorage.items = $scope.cart; // you should do this for(var i=0; i<$scope.cart.length; i++) { $localStorage.items.push($scope.cart[i]); } } 
Source Link
Pawan Nogariya
  • 9k
  • 14
  • 61
  • 137

Yes because you are not adding items to your items and cart variables but every time assigning them completely new values. You are re-initializing them everytime and so they loose last added values.

You should do something like this

if ($scope.cart != 0) { // instead of this //$localStorage.items = $scope.cart; // you should do this for(var i=0; i<$scope.cart.length; i++) { $localStorage.items.push($scope.cart[i]); } }