简体   繁体   中英

Angularjs ng-repeat index not working

I want to use ng-repeat more or less as follows:

<div ng-repeat="One_Entry in Entries_List track by One_Entry.Entry_ID"
     onClick="DoSomething(One_Entry.Entry_ID)">

      <!--- 
      present various fields within "One_Entry"
      -->

</div>

Entries_List is a JSON array of objects, being Entry_ID one of the elements within the object.

DoSomething is a function within the related controller that is supposed to perform a specific activity on the structure whose ID is the passed Entry_ID.

I tried using $index as well as $parent.$index but I'm getting an error stating that these variable do not exist.

Could anyone tell me how I can achieve the above functionality?

Thanks.

The object One_Entry is scoped. Therefore onclick won't work. Use ng-click instead which is the Angular version for onclick:

<div ng-repeat="One_Entry in Entries_List track by One_Entry.Entry_ID"
     ng-click="DoSomething(One_Entry.Entry_ID)">

  <!--- 
  present various fields within "One_Entry"
  -->

</div>

It's not OnClick it's ng-click

Change

From :

<div ng-repeat="One_Entry in Entries_List track by One_Entry.Entry_ID"
 onClick="DoSomething(One_Entry.Entry_ID)">

To:

 <div ng-repeat="One_Entry in Entries_List track by One_Entry.Entry_ID"
     ng-click="DoSomething(One_Entry.Entry_ID)">

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM