angularjsangularjs-ng-repeatlocal-storageng-storage

How to increment & decrement a json value from local storage using angular.js


How to Increment and decrement a json value from local storage using angular.js

I use ngstorage module from angularjs .

my Plunker


Solution

  • You need to pass item object while calling increment & decrement function

    Markup

    <li data-ng-repeat="item in data">
        <span>
            id:{{ item.id }} 
          <button ng-click="increment(item);">+</button>
          age:{{ item.age }}
          <button ng-click="decrement(item);">-</button>                        
          <button data-ng-click="delItem(item)">X</button>
        </span>
    </li>
    

    Code

    $scope.increment = function (item) {
        if (item.age >= max) { return; }
        item.age++;
    };
    $scope.decrement = function (item) {
        if (item.age <= min) { return; }
        item.age--;
    };
    

    Demo Plunkr