3

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});
        }
 }
4
  • 3
    Can you show your code? Commented Apr 25, 2017 at 6:50
  • can you add the code which you tried Commented Apr 25, 2017 at 6:51
  • I already updated my post Commented Apr 25, 2017 at 6:58
  • Still a problem? I understand your real problem is the validation. Can you clarify your question? Also maybe a good aproach is by using Reactive Forms: angularfirebase.com/lessons/basics-reactive-forms-in-angular Commented Dec 12, 2018 at 14:28

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.