1

I'm not sure how to do this in angular, after coming from jquery.

I have a table:

<div class="col-xs-10">
<table>
<thead>
  <tr>
    <th>A</th>
    <th>B</th>
    <th>C</th>
</thead>
<tbody ng-repeat="val in data">
  <tr>
    <td>val.Time</td>
    <td>val.Distance</td>
    <td ng-click="callmethod()"><img src="delete"></td>
  </tr>
</tbody>
</table>
</div>

Essentially I want the callmethod() to know which row is being clicked so that I can make a update in the model in my controller. What is the right way to do this?

1
  • 1
    just pass the object as argument Commented Sep 12, 2014 at 17:56

2 Answers 2

1

You can use the $index property:

callmethod($index)

Then on your controller you would do something like:

function callmethod(index) {
   var foo = $scope.data[index];
}
Sign up to request clarification or add additional context in comments.

Comments

0

Change that ng-click to this:

<td ng-click="callmethod(val)"><img src="delete"></td>

You'll get the whole val object when that method gets called.

Comments

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.