67

I have a click event nested one level. When i click on the child the expected function is called but the parent's function is also called. Here is the code

<li class="task-item" *ngFor="let task of tasks" (click)="showTask(task.name)">
    <input type="checkbox" [ngModel]="task.taskStatus" (ngModelChange)="changeTaskStatus($event)" />
</li>

So when the checkbox changes changeTaskStatus() and the showTask() called together. I want the parent to keep quiet when checkbox changes. How do I achieve this? It was easy to handle this in Angular 1

Things I've tried that failed

Used $event.stopPropagation() in the checkbox's click event that changed nothing

<input type="checkbox" [ngModel]="task.taskStatus" (click)="$event.stopPropagation()" (ngModelChange)="changeTaskStatus($event)" />
halfer
  • 19,824
  • 17
  • 99
  • 186
Ashik Basheer
  • 1,531
  • 3
  • 16
  • 36
  • I figured it out. I had a custom CSS on the checkbox that was causing the problem. – Ashik Basheer Dec 29 '16 at 14:46
  • Please add your solutions in an answer box, rather than as edits to the question. Thank you. – halfer Dec 29 '16 at 19:32
  • Thanks. works like a charm – Sacky San Apr 20 '20 at 23:08