Home  >  Article  >  Backend Development  >  javascript - In angularJS, if you click on the current element in the attribute element in the ng-repeat array object, operate on it

javascript - In angularJS, if you click on the current element in the attribute element in the ng-repeat array object, operate on it

WBOY
WBOYOriginal
2016-09-21 14:13:124997browse

javascript - In angularJS, if you click on the current element in the attribute element in the ng-repeat array object, operate on itFor 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?
javascript - In angularJS, if you click on the current element in the attribute element in the ng-repeat array object, operate on it 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!

Reply content:

javascript - In angularJS, if you click on the current element in the attribute element in the ng-repeat array object, operate on itFor 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?
javascript - In angularJS, if you click on the current element in the attribute element in the ng-repeat array object, operate on it 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

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn