lundi 2 août 2021

mat-checkbox check on method result

I have a mat-checkbox, and when I click it I show a mat-dialog component, and if the user clicks "confirm" I want the checkbox to become checked, if they press cancel, I want it to remain unchecked, how do I do this?

Here is the method that the checkbox calls when clicked:

onShowDialog(): void {
    const dialogRef = this.dialog.open(ConfirmActionDialogComponent, {
      width: '250px',
      data: { title: 'Enable publish?'}
    });

    dialogRef.afterClosed().subscribe(result => {
      if (result) {
        return true;
      }
    });
  }
<mat-checkbox *ngIf="settingsChanged" (change)='onShowDialog($event)' formControlName="automaticallyPublish">Checkbox name</mat-checkbox>



Aucun commentaire:

Enregistrer un commentaire