For example, I want to display this simulated data array object using ng-repeat loop page. When I click, I want to increase the count of the selected object by 1. How do I get this current element?
What if so! I want to get support and add +1 to support. Gid is the ID of the work, but each ID can only +1, similar to the like function!
For example, I want to display this simulated data array object using ng-repeat loop page. When I click, I want to increase the count of the selected object by 1. How do I get this current element?
What if so! I want to get support and add +1 to support. Gid is the ID of the work, but each ID can only +1, similar to the like function!
$index
can get the subscript of the element in the array, and then get the element based on the subscript
<code><div ng-repeat="item in tTarvel" ng-click="item.count++">{{ item.count }}</div></code>
Add the ng-click method to the element li in ng-repeat and get the current element through $event.target
<code><ul> <li ng-repeat="item in items track by $index"> {{item.name}} <button ng-click="addItem($index)">{{itemNumber}}</button> </li> </ul> <script> $scope.itemNumber=0; $scope.addItem=function($index){ angular.forEach($scope.items,function(item,index){ if($index==index){ $scope.itemNumber++; } }) } </script></code>
My personal implementation method is probably like this