title: How to close parent dialog depending on selected answer in confirm child dialog in Angular?
body: <p>I'm trying to close a parent mat-dialog depending on the answer to a child confirm mat-dialog in Angular.  The child confirm dialog says &quot;You have unsaved changes.  Are you sure you want to close?&quot;  If the user clicks YES then both dialogs are supposed to close.  If they say NO, then only the confirm dialog is supposed to close.  The NO works but not the the YES.</p>
  <p>Here is the template with the two buttons</p>
  <pre><code>&lt;mat-dialog-actions align=&quot;end&quot;&gt;
    &lt;button
      mat-button color=&quot;accent&quot; (click)=&quot;save()&quot; [mat-dialog-close]=&quot;true&quot; cdkFocusInitial
    &gt;Save
    &lt;/button&gt;
    &lt;button mat-button (click)=&quot;openConfirmDialog()&quot;&gt;cancel&lt;/button&gt;
  &lt;/mat-dialog-actions&gt;
  </code></pre>
  <p>The following snippets are in the parent dialog:</p>
  <pre><code>  constructor(
      public dialog: MatDialog,
      public parentDialogRef: MatDialogRef&lt;ParentDialogComponent&gt;,
  </code></pre>
  <p>The confirm dialog pops up when the user clicks the SAVE button in the parent dialog.  The child confirm dialog has a reference to the parent dialog when it opens so that it can close it.</p>
  <pre><code>  openConfirmDialog() {
      const dialogRef = this.dialog.open(ConfirmDialogComponent, {
        message: &quot;You have unsaved changes. Are you sure you want to close?&quot;
      });
      dialogRef.afterClosed().subscribe(result =&gt; {
        if (result=='true') {
          console.log('result=',result,parentDialogRef=',this.parentDialogRef);
          this.parentDialogRef.close();
        }
      })
    }
  </code></pre>
  <p>The console.log shows a result of 'true' and a valid parentDialogRef, yet the parent dialog fails to close when the user selects YES.</p>
  <p>Here is the confirm dialog .ts code:</p>
  <pre><code>import {Component, Inject} from '@angular/core';
  import {MatDialog, MatDialogRef, MAT_DIALOG_DATA} from '@angular/material/dialog';
  
  @Component({
    selector: 'app-confirm-dialog',
    templateUrl: './confirm-dialog.component.html',
    styleUrls: ['./confirm-dialog.component.css']
  })
  export class ConfirmDialogComponent {
    constructor(
      public dialogRef: MatDialogRef&lt;ConfirmDialogComponent&gt;,
      @Inject(MAT_DIALOG_DATA) public message: string) {
      dialogRef.disableClose = true;
    }
  }
  </code></pre>
  <p>I want this code to be generic so that it can be used by any other component.</p>
  <p>Suggestions?</p>