question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Bug MatDialog is unclosable

See original GitHub issue

Bug, feature request, or proposal:

Bug

What is the expected behavior?

Should be able to close dialog

What is the current behavior?

Cannot close dialog - for a predictable/certain code path

What are the steps to reproduce?

Here is the problem: https://www.useloom.com/share/7eb9c523ee3144fb94bb2b49b57dee1b

Which versions of Angular, Material, OS, TypeScript, browsers are affected?

Angular5, Material2, MacOS, tsc version 2.6.1

More info

in both cases, the dialog is created using the same code, here is the code to create dialog:


'use strict';

import {Component, OnInit, Inject, Injectable} from '@angular/core';
import {MainDataService} from '../../services/main';
import {MAT_DIALOG_DATA, MatDialogRef, MatDialogConfig} from '@angular/material';
import {MatDialog} from '@angular/material/dialog';

@Component({
  templateUrl: './stop-recording-dialog.component.html',
  styleUrls: ['./stop-recording-dialog.component.scss']
})

export class StopRecordingDialogComponent implements OnInit {
  
  public dialogResult: any;
  escapeToClose = true;
  
  constructor(public dialogRef: MatDialogRef<StopRecordingDialogComponent>,
              @Inject(MAT_DIALOG_DATA) public data: string,
              private mds: MainDataService) {
  }
  
  onClickClose() {
    this.dialogRef.close();
    this.mds.dialogEmitter.emit({
      name: 'stop-recording-run-dialog-closed',
      value: 'x'
    });
  }
  
}


@Injectable()
export class StopRecordingDialog {
  
  escapeToClose = true;
  dialogRef: MatDialogRef<StopRecordingDialogComponent> | null;
  
  config = Object.assign(new MatDialogConfig(), {
    width: '600px',
    data: 'This text is passed into the dialog!'
  });
  
  constructor(public dialog: MatDialog, private mds: MainDataService) {}
  
  openDialog() {
    
    this.dialogRef = this.dialog.open(StopRecordingDialogComponent, this.config);
    
    this.dialogRef.beforeClose().subscribe((result: string) => {
      console.log(`Dialog before closed: ${result}`);
    });
    
    this.dialogRef.afterClosed().subscribe(result => {
      console.log(`Dialog after closed: ${result}`);
    });
    
  }
}

even when it fails to close, the onClickClose() method is called, so not sure why the dialog won’t close.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:17 (15 by maintainers)

github_iconTop GitHub Comments

7reactions
jelbourncommented, Jan 31, 2018

Closing since this does sound like an issue with escaping the Angular zone. You can re-enter the zone by injecting NgZone and doing

ngZone.run(() => {
   dialog.close();
});
2reactions
willshowellcommented, Jan 30, 2018

@ORESoftware I actually don’t have any Angular 1 experience, so I dunno. The root of this issue is that your browser extension callback is not executing within the NgZone. You can probably pull the ngZone.run() part into this.mds so that it’s consolidated better and not left to your dialog service to handle.

It’s a common issue when incorporating 3rd party libs/apis.

Read more comments on GitHub >

github_iconTop Results From Across the Web

MatDialog dialog from Angular Material is not closing
If you have an error occurring in the ngOnChanges of another component it can cause this un-closable dialog behavior.
Read more >
How to use Mat-Dialog in Angular ? - GeeksforGeeks
First we need to import 'MatDialog' from '@angular/material/dialog' and we need to create an instance for it in the constructor.
Read more >
Disable click outside of angular material dialog area to close ...
In the method that opens the dialog, pass in the following configuration option disableClose as the second parameter in MatDialog#open() and set it...
Read more >
Dialog | Angular Material
The MatDialog service can be used to open modal dialogs with Material Design styling and animations. Dialog Overview.
Read more >
Angular Material Dialog: A Complete Example
In this post, we are going to go through a complete example of how to build a custom dialog using the Angular Material...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found