首页 > 解决方案 > 在Angular中使用复选框选择列

问题描述

我当前的项目要求通过选中复选框来获取所选列的值。通常我们会在行中添加复选框,我们会得到值。任何人都可以指导我,这可能吗?如果可以,你能建议怎么做吗?

谢谢,萨拉

标签: angularcheckbox

解决方案


假设下面是您显示数据的表格

<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);
}

希望能帮助到你


推荐阅读