3

How I pass an object as a parameter in a ng-click within a ng-repeat?

Example:

<tr data-ng-repeat="table in tables">
    <td>{{ table.name }}</td>
    <td>{{ isActive(table.active) }}</td>
    <td>{{ table.initialDate }}</td>
    <td>{{ table.finalDate }}</td>
    <td>
        <button data-ng-click="updateTable(table)">Update</button>
    </td>
</tr>

Inside the ng-click updateTable(HERE), I want to pass my object table.

Can someone help me?

3
  • last time I tried that it worked. what are you getting with updateTable(table)? You could use $index as updateTable($index) and inside your function tables[$index] but as I said your first attempt seems fine from my end Commented Feb 9, 2015 at 23:58
  • Omg, I tested here and if I change my function for print table.name the function prints test. Forget it please, but thankyou for your attention!!!!! Commented Feb 10, 2015 at 0:05
  • You should post your find as your answer or close your question to remove it from the pool. Stack prefers if you post your own answer instead of closing it. Commented Feb 10, 2015 at 0:08

1 Answer 1

1

In your component.html edit your code as shown below :

<td><button (click)=updateTable(table)>Update</button></td></tr>

then in your typescript code just declare the function

updateTable(table){
  console.log(table); //write your own code here!.
}
Sign up to request clarification or add additional context in comments.

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.