简体   繁体   English

检查 mat-dialog 是否已经打开

[英]Check if mat-dialog is already open

Goal : Open dialog on page load.目标:在页面加载时打开对话框。 Check to make sure its not already open so it only opens once.检查以确保它尚未打开,因此它只打开一次。 The dialog is a separate component.该对话框是一个单独的组件。

Problem : Its opening twice.问题:它打开了两次。

I tried checking, but the condition never becomes true.我尝试检查,但条件永远不会变为真。 I was using information from SO articles like Angular Material |我正在使用 SO 文章中的信息,例如Angular 材料 | Check if dialog is open but they mention MatDialogRef? 检查对话框是否打开但他们提到 MatDialogRef?

TS :技术人员

  ngOnInit()  
  {   
    
    // Set InActiveV back to false incase p refreshes page so that chat will call StartPVQueue
    sessionStorage.setItem('InActiveV', "false");

    // Start visit in API and get medical info    
    const staring = timer(500, 10000);
    this.startVSubscription = staring.subscribe(val =>{
      if (!this.isLoad) {
        this.PStartV();
        //this.cmdOpenDialog_OnInit();
      }
      else {
        this.startVSubscription.unsubscribe();
      }
    });
      this.cmdOpenDialog_OnInit();
  }

cmdOpenDialog_OnInit() {
    if (!this.dialog) {
                return;
            }
    this.dialog.open(DialogInternalNotesThreeComponent, {
        data: {
            data: this.internalNotes
        }
    }); 
}

You can store a reference to the dialog on your component:您可以在组件上存储对对话框的引用:

cmdOpenDialog_OnInit() {
  if(this.dialogRef) {
    return;
  }
  this.dialogRef = this.dialog.open(DialogInternalNotesThreeComponent, {...});
  this.dialogRef.afterClosed().subscribe(() => {
    this.dialogRef = null;
  })
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM