0

I have pairs of [value, checkbox] with the following structure

<tr *ngFor="let element of elements">
  <td>{{ element.id }}</td>

  <td>
    <label class='checkbox'>
      <input type='checkbox'>
    </label>
  </td>
</tr>

How do I catch a click on checkbox and then capture corresponding value so I can send it to server as s parameter?

Thanks in advance.

2 Answers 2

1

Just listen for the event and invoke a callback function when it occurs.

<label class='checkbox'>
  <input type='checkbox' (click)="send($event.currentTarget.checked)"> Click Me!
</label>

Demo

Sign up to request clarification or add additional context in comments.

Comments

1

Simply pass your array iteration value using function to the server like this.

<tr *ngFor="let element of elements">
  <td>{{ element.id }}</td>

  <td>
    <label class='checkbox'>
      <input type='checkbox' (click)='getValue(element)'>
    </label>
  </td>
</tr>

function getValue(value){
   console.log(value);
}

Comments

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.