blu*_*oud 3 onchange event-propagation
<mat-checkbox (change)="handleProductClick(children, $event)" [(ngModel)] = "children.selected"
[name]="children.grpId" [id]="children.id"></mat-checkbox>
handleProductClick(selectedProd : Product, event: any)
{
event.stopPropagation();
}
Run Code Online (Sandbox Code Playgroud)
如果我使用单击功能而不是更改,则可以正常工作。虽然我无法使用click。我必须坚持改变。有没有办法从change函数调用stopPropagation?如果不是,我还能做些什么来阻止事件传播?
我知道了 必须同时使用复选框和单击复选框。我已经尝试过了。唯一的区别是我在click方法中调用了一个函数,但从未调用过它。如果您在模板中的click方法上调用$ event.stopPropagation,则效果很好。奇怪。以下答案解决了我的问题。Angular 2防止在单击子级时单击父级
<mat-checkbox (change)="handleProductClick(children, $event)"[checked]="children.selected" (click)="$event.stopPropagation()"
[name]="children.grpId" [id]="children.id"></mat-checkbox>
| 归档时间: |
|
| 查看次数: |
1418 次 |
| 最近记录: |