How to increment & decrement a json value from loc

2019-07-22 05:30发布

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

I use ngstorage module from angularjs .

my Plunker

1条回答
forever°为你锁心
2楼-- · 2019-07-22 05:51

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

查看更多
登录 后发表回答