我很难获得角度2中的复选框的值,我已经使用(更改)来获取复选框的值,实际上它可以工作但我是我很难验证我的项目,所以如果你能帮我找到一个获得复选框价值的好方法,请告诉我。
这是我的HTML代码
<table>
<tr>
<th>Employee Name</th>
</tr>
<tr *ngFor= "let employee of employeeData" >
<td>
<div class="checkbox">
<label>
<input type="checkbox" value="{{employee.id}}" (change)="EmployeeCheckbox(employee.id,employee.firstname,employee.lastname)">
{{employee.firstname}} {{employee.lastname}}
</label>
</div>
</td>
</tr>
这是我的.ts代码
employeesList=[];
EmployeeCheckbox(id:any,first:any,last:any){
let name = first + " " + last;
let len = this.employeesList.length;
let add = false;
for (var i = 0; i < len; i++) {
if (id == this.employeesList[i].id){
add = true;
if (i > -1) {
this.employeesList.splice(i, 1);
}
}
}
if(add==false){
this.employeesList.push({id,name});
}
}