[英]Check if mat-dialog is already open
目标:在页面加载时打开对话框。 检查以确保它尚未打开,因此它只打开一次。 该对话框是一个单独的组件。
问题:它打开了两次。
我尝试检查,但条件永远不会变为真。 我正在使用 SO 文章中的信息,例如Angular 材料 | 检查对话框是否打开但他们提到 MatDialogRef?
技术人员:
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
}
});
}
您可以在组件上存储对对话框的引用:
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.