简体   繁体   English

我如何在 ng-repeat 中的 ng-click 中将对象作为参数传递? AngularJS

[英]How I pass an object as a parameter in a ng-click within a ng-repeat? AngularJS

How I pass an object as a parameter in a ng-click within a ng-repeat?我如何在 ng-repeat 中的 ng-click 中将对象作为参数传递?

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.在 ng-click updateTable( HERE ) 中,我想传递我的对象表。

Can someone help me?有人能帮我吗?

In your component.html edit your code as shown below :在您的 component.html 中编辑您的代码,如下所示:

<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!.
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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