禁用 PrimeNG 复选框
Disabling PrimeNG checkbox
我试图在某些情况下使用 disabled
属性 禁用 PrimeNG 复选框并将其设置为 true。但是,每次禁用该复选框并单击它时,它都会刷新页面并将我带到根页面 /#
。
作为测试,我尝试手动禁用复选框:
<p-checkbox [ngModel]="visibleInReport()" (click)="$event.stopPropagation()" [disabled]="true" binary="true" (onChange)="toggleSelection($event)"></p-checkbox>
在我的组件中,toggleSelection()
函数如下:
toggleSelection(event) {
console.log("Updating TherapyMatch Visibility");
this.therapyService.updateReportVisability(this.revisionId, this.therapy.id, event).subscribe((res) => {
console.log(res);
});
}
disabled
属性 是否是防止单击此复选框时发生任何操作的正确方法?
Is the disabled
property the correct way to prevent any action from
occurring when this checkbox is clicked ?
是的。而且您不需要管理 click
事件。
看看这个 StackBlitz 我刚刚使 disabled
属性 动态化。
我试图在某些情况下使用 disabled
属性 禁用 PrimeNG 复选框并将其设置为 true。但是,每次禁用该复选框并单击它时,它都会刷新页面并将我带到根页面 /#
。
作为测试,我尝试手动禁用复选框:
<p-checkbox [ngModel]="visibleInReport()" (click)="$event.stopPropagation()" [disabled]="true" binary="true" (onChange)="toggleSelection($event)"></p-checkbox>
在我的组件中,toggleSelection()
函数如下:
toggleSelection(event) {
console.log("Updating TherapyMatch Visibility");
this.therapyService.updateReportVisability(this.revisionId, this.therapy.id, event).subscribe((res) => {
console.log(res);
});
}
disabled
属性 是否是防止单击此复选框时发生任何操作的正确方法?
Is the
disabled
property the correct way to prevent any action from occurring when this checkbox is clicked ?
是的。而且您不需要管理 click
事件。
看看这个 StackBlitz 我刚刚使 disabled
属性 动态化。