How to get the value of a checkbox in angular 2
I am having a hard time finding the value of a checkbox in angular 2, I already use (change) to get the value of that checkbox, it actually works, but it's hard for me to validate my project, so if you can help me find a good way to get the value of a checkbox, just tell 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});
}
}
+3
source to share
No one has answered this question yet
See similar questions:
or similar: