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?

Lucas
  • 1,251
  • 4
  • 16
  • 34
  • 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 – Dalorzo Feb 09 '15 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!!!!! – Lucas Feb 10 '15 at 00: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. – WebWanderer Feb 10 '15 at 00:08

1 Answers1

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!.
}
manar odeh
  • 111
  • 3