javascript - How to reset count in AngularJs -


i have list 4 items. each item have counter. when click on item, count increase. want reset counter value 0 except clicking item. demo.

var myapp = angular.module('myapp',[]);  var jsoninfo = {"count":[{"name":"one",count:0} ,{"name":"two",count:0},{"name":"three",count:0} ,{"name":"four",count:0}]}  function myctrl($scope) {   $scope.data =jsoninfo;    $scope.count = function (inc) {     inc.count =  inc.count + 1   }; } 

you can try this. loop on items , check if clicked item current one: increment , others set 0.

try demo

var myapp = angular.module('myapp',[]);  var jsoninfo = {"count":[{"name":"one",count:0} ,{"name":"two",count:0},{"name":"three",count:0} ,{"name":"four",count:0}]}  function myctrl($scope) {   $scope.data =jsoninfo;    $scope.count = function (inc) {      jsoninfo.count.foreach((item) => {         item.count = item.name === inc.name? inc.count + 1 : 0;       });   }; } 

Comments

Popular posts from this blog

python - Operations inside variables -

Generic Map Parameter java -

arrays - What causes a java.lang.ArrayIndexOutOfBoundsException and how do I prevent it? -