I want to manually modify the value of an input checkbox by clicking everywhere on its html parent.
Here is my HTML:
<div (click)="onChange($event)" class="option" *ngFor = "let option of answerForm.options">
<input type="checkbox" name="{{answerForm.type}}{{answerForm.id}}" value="{{option}}">
<label>{{option}}</label>
</div>
Here is my typescript:
onChange($event): void {
if ($event.target !== $event.currentTarget) {return;}
$event.target.children[0].checked = !$event.target.children[0].checked;
}
The event works correctly when I click on the div.
When I click on the label, the event is trigger, with the label as a target and doesn't pass the condition as expected.
I expect the event propagation to automatically trigger the event for the parent, but it doesn't. It seems to be the default behavior of Angular but I am not really sure.
Do you have any solution to only trigger the click event for the div wherever the click is made on it ?