How to increment & decrement a json value from loc

2019-07-22 05:22发布

问题:

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

I use ngstorage module from angularjs .

my Plunker

回答1:

You need to pass item object while calling increament & decreament 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