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

WBOY
Release: 2016-09-21 14:13:12
Original
5032 people have browsed it

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>
Copy after login

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>
Copy after login

My personal implementation method is probably like this

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template