异步代码中带有 matDialog 的 canDeactivate

问题描述

我无法从异步代码中捕获 matDialog 响应。下面是展示我的实现的代码片段。

guard.ts

export class CanDeactivateGuard
implements CanDeactivate<ComponentCanDeactivate> {
constructor(private modalService: MatDialog,private testing: TestingService) {}

canDeactivate(
  component: ComponentCanDeactivate
): Observable<boolean> | Promise<boolean> | boolean {
  
  //calling a service to check if user has access to forms
  return this.testing.test().toPromise()
   .then(res => {
    const dialogRef = this.modalService.open(DialogComponent,{
      width: '600px',height: '250px'
    });

    return dialogRef.afterClosed().pipe(
      map(result => result === true)
     );  
    })
   .catch(() => return true); // user navigate away if does not have permission
   }
  }

但是此代码无法在对话框中获取用户操作的输入。 我无法找到可能是什么问题以及如何在异步代码中处理 matDialog。我很想知道如何处理这种情况。

注意:这是非常通用的代码示例,而不是实际代码。如果您需要额外的信息来理解场景,请发表评论

提前致谢。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...