I have a matcheck in my angular app. I am disabling the checkbox based on some condition. it works when the screen loads initially. There is a scenario, where on click of a button, a mat-dialog is open. when I click 'CANCEl' , on mat-dialog, I still call disableChkBox method, but the checkbox is enabled.
<mat-checkbox style="padding-top: 0px;" [disabled]="disableChkBox()" formControlName = "mycheckbox" value = "cbx1" id = "mycheckbox" checked = "false">
<mat-label>Include Average ratio</mat-label></mat-checkbox>
<button mat-raised-button id="btn" color="primary" (click)="displayConfirmDialog()">Dialog Open</button>
Component.ts
disableChkBox() {
if(this.myform.controls['name'].value === 'dave' && (this.apprepubForm.get('age').value === '45') {
return true;
} else {
return false;
}
}
displayConfirmDialog() {
dialogRef.afterClosed().subscribe((res) => {
this.disableChkBox();
})
}