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

≯℡__Kan透↙ 提交于 2019-12-24 05:32:17

问题


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



来源:https://stackoverflow.com/questions/30505010/how-to-increment-decrement-a-json-value-from-local-storage-using-angular-js

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!