In javascript-angularJS, if you click to obtain the current element in the attribute element of the ng-repeat array object, perform operations on it.

Source: Internet
Author: User
For example, I want to use the ng-repeat loop page to display the simulated data array object. I want to click the selected count + 1. how can I get the current element? if so! I want to get support and operate on support + 1. gid is the id of the file...

For example, I want to use the ng-repeat loop page to display the simulated data array object. I want to click the selected count + 1. how can I get this current element?
If so! I want to get support and operate on support + 1. gid is the id of the work, but each id can only be + 1, similar to the like function!

Reply content:

For example, I want to use the ng-repeat loop page to display the simulated data array object. I want to click the selected count + 1. how can I get this current element?
If so! I want to get support and operate on support + 1. gid is the id of the work, but each id can only be + 1, similar to the like function!

$indexYou can obtain the subscript of an element in the array, and then obtain the element according to the subscript.

{{ item.count }}

Add the ng-click method to the element li in ng-repeat, and obtain the current element through event.tar get.


  
  • {{item.name}} {{itemNumber}}
《script》 $scope.itemNumber=0; $scope.addItem=function($index){ angular.forEach($scope.items,function(item,index){ if($index==index){ $scope.itemNumber++; } }) }《script》

My personal implementation method is probably like this

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.