I'm having a hard time in getting the value of the checkbox in angular 2, I already use (change) just to get the value of the checkbox, actually it works but I'm having a hard time to validate my project, so if you could help me to find a good way to get the value of the checkbox, just please inform me.
this is my html code
<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>
this is my .ts code
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});
}
}