angular - 在Angular中使用复选框选择列
问题描述
我当前的项目要求通过选中复选框来获取所选列的值。通常我们会在行中添加复选框,我们会得到值。任何人都可以指导我,这可能吗?如果可以,你能建议怎么做吗?
谢谢,萨拉
解决方案
假设下面是您显示数据的表格
<tbody>
<tr *ngFor="let item of employee">
<td><input type="checkbox" [(ngModel)]="isChecked" (change)="getValue(item)" /></<td>
<td>{{item.name}}</td>
<td>{{item.surname}}</td>
<td>{{item.code}}</td>
</tr><tbody>
以下是您在组件上的方法
getValue(event: any){
// you will get the row value here when you check your checkBox
console.log(event);
}
希望能帮助到你
推荐阅读
- c# - LINQ Include 未按预期工作 .net core 3.1
- nim-lang - 尝试返回时出现“错误:未声明的标识符”
从一个程序 - java - 应用程序可在模拟器(和通过 USB 的设备)上运行,但从 GooglePlay 商店下载时无法运行?
- c - 二叉树中的搜索键
- ios - 无法解决线程 1:致命错误:索引超出范围
- javascript - addEventListener 没有链接到元素 ID?
- visual-studio-code - VS Code 中的多个游标
- flutter - 获取价值时出现 FlutterSecureStorage 问题
- r - 在 R 回归中循环不同的变量和数据集
- python - 如何将具有相似列的行写入新表