问题描述
我无法从异步代码中捕获 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 (将#修改为@)