Search code examples
angularmat-dialog

close dialog from snackbar


I have a dialog that can be closed by a snackbar. My code closes the dialog, but I need to move the mouse to get it. So I guess that somehow the view is stuck.

private save(element: myModel) {

  this.myService.save(element).then(() => {
      this.snackBar.open('saved','ok', {duration: 1000})
      .afterDismissed().subscribe(() => {
        this.dialogRef.close(element.id);
      })
    );
  });
}

How can I get it just closed without the needed of moving the mouse?


Solution

  • You might want to try using deley operator:

        this.snackBar
          .open('saved', 'ok', { duration: 1000 })
          .afterDismissed()
          .pipe(delay(0))
          .subscribe(() => this.dialogRef.close())