如何在更改 mat-checkbox 时停止调用函数的事件传播?

How to stop event propagation on calling a function on change of mat-checkbox?

<mat-checkbox (change)="handleProductClick(children, $event)"  [(ngModel)] = "children.selected"
[name]="children.grpId" [id]="children.id"></mat-checkbox>

handleProductClick(selectedProd : Product, event: any)
{
  event.stopPropagation();
}

如果我使用点击功能而不是更改功能,它就可以正常工作。虽然我不能使用点击。我必须坚持改变。有没有办法从 change 函数调用 stopPropagation ?如果不是,我还能做些什么来阻止事件传播?

我成功了。必须在复选框上同时使用单击和更改。我之前试过。唯一的区别是我在 click 方法中调用了一个函数,但它从未被调用过。如果您在模板中的 click 方法上调用 $event.stopPropagation,效果很好。奇怪的。下面的答案解决了我的问题。

<mat-checkbox (change)="handleProductClick(children, $event)"[checked]="children.selected" (click)="$event.stopPropagation()" [name]="children.grpId" [id]="children.id"></mat-checkbox>