angular - 如何在打字稿中单击表格中的按钮时获取动态表格行数据
问题描述
我正在使用动态表,每行都有一个按钮,单击按钮时,我需要单击相应行按钮的数据。
我已经尝试过(点击)事件绑定,我得到的输出是未定义的。
<table>
<thead> <tr> <th> Name </th> <th> Company </th> </tr> </thead>
<tr *ngFor = "let employee of employees" (click) = "removeEmployee(row)">
<td> <input type="text" [(ngModel)]= "employee.name"></td>
<td> <input type="text" [(ngModel)] = "employee.companyName"> </td>
</tr>
</table>
.ts 文件
removeEmployee(tr) {
console.log(tr);
}
预期:单击按钮时,应输出表格行数据。
实际:显示未定义。
解决方案
更改员工行:
<tr *ngFor = "let employee of employees" (click) = "removeEmployee(employee)">
推荐阅读
- html - 隐藏带有条件的 Primeng 上下文菜单
- javascript - Discord.js 随机角色反应
- vb.net - 最近文件列表的位置 vb.net
- java - 将 DTO 用作另一个 DTO 中的字段
- php - 如何在刀片中制作多维数组并使用 laravel 5.5+ 将其发送到控制器
- string - HOCON 转义双引号
- azure - 在用户之间分摊启用 Azure 语音的机器人的成本
- javascript - 如何做 z-index 的反向功能
- xamarin - 如何获得网络速度,在 xamarin iOS 中是快还是慢?
- python - 我怎么知道在 Android 上运行 selenium