1

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.

2 Answers 2

1

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>
Sign up to request clarification or add additional context in comments.

4 Comments

I wrote the following: ng-click="alert('ggg')" and nothing happened (no alert, no error message. Nothing.
Alert is not a function unless you create it in the controller by $scope.alert = function(txt) {alert(txt);}. Then you can call it by ng-click="alert('ggg')".
Btw, is the function DoSomething created in the controller and added to the $scope? Like $scope.DoSomething = function () { //Do something }
GOOD CATCH!!!!! The @scope. was missing in the function declaration within the controller. Now it works perfectly. Thanks @NiklasMH!!!
0

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)">

3 Comments

Well, the problem does not seam to be there because the function is fired (i.e. if I deploy within the function a simple alert, I get the message). On the other hand, if I use ng-click, the function is not fired at all.
can you creatae a plunker or jsfiddle
Thanks @Sajeetharan for your response. Please see my last comment to the previous solution. My error was that the function to be invoked was missing the $scope. prefix within the controller.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.