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

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -