代码之家  ›  专栏  ›  技术社区  ›  Vingtoft

角度材质检查对话框是否打开

  •  1
  • Vingtoft  · 技术社区  · 6 年前

    我正在使用 Angular Material dialog 在我的应用程序中显示警告消息。

    我需要检查是否已经打开了这样的对话框:

    private _openDialog() {
      // if (this.dialog.isOpen()) return; <-- NOT WORKING
      this.dialog.open(WarningComponent, {
        width: '450px',
        height: '380px',
      });
    

    }

    问题: 是否有任何方法可以检查“角度材质”对话框是否已打开?

    2 回复  |  直到 6 年前
        1
  •  5
  •   Maryannah    6 年前

    如果它在单个组件中,只需存储对操作它有用的引用。

    private _openDialog() {
      if (!this.dialogRef) return;
      this.dialogRef = this.dialog.open(WarningComponent, {
        width: '450px',
        height: '380px',
      });
    
      this.dialogRef.afterClosed().pipe(
        finalize(() => this.dialogRef = undefined)
      );
    }
    

    如果是跨组件的,请检查打开的对话框列表:

    private _openDialog() {
      if (!this.dialog.openDialogs || !this.dialog.openDialogs.length) return;
      this.dialog.open(WarningComponent, {
        width: '450px',
        height: '380px',
      });
    }
    
        2
  •  -2
  •   Vingtoft    6 年前

    你能看一下这个链接吗 check existing of open dialog

    private _openDialog() {
      // Only show if not already open
      if ($('.mat-dialog-container').length > 0) return;
      this.dialog.open(WarningComponent, {
         width: '450px',
         height: '380px',
      });
    }