angular - 等待模态响应时冻结代码块
问题描述
这个想法是当用户处理某事并尝试运行一些敏感组件时,他需要确认密码。这样,我们就可以对用户进行身份验证。确认密码对话框如下所示:
appGlobal.service.ts 中的方法
OpenACLModal() {
this.aclModal.open(AccessControlListComponent, { width: '450px' });
}
这是 access-control-list.service.ts 中的 Open 方法
//Open a new dialog window with the specified configuration.
open(content: any, config: MatDialogConfig = {}): MatDialogRef<any> {
const dialog = this.dialog.open(content, config);
this.stack.push(dialog);
return dialog;
}
所以,现在我可以在 appGlobal.service.ts 中引用的一行代码中触发我的模式
let modal = this.appGlobal.OpenACLModal();
当我在模态上单击确定时,我执行以下操作:
AuthUser() {
let auth = new Authorize();
auth.Credentials.CredentialsData1 = this.email;
auth.Credentials.CredentialsData2 = this.password;
this.http.post(this.appGlobal.BASE_SERVER_ADDRESS + 'api/AppServer/Authorize', auth).subscribe((res) => {
if (res['IsAuthorized'] == true) {
// do something
}
else // do something
});
}
问:我想做类似的事情:
let modal = this.appGlobal.OpenACLModal();
if (modal==true)
{
// I want to freeze code here and wait for the response of modal
// Check response if true
// do something
}
else alert("You don't have permission to perform this kind of action");
怎么做?感谢任何人。
解决方案
推荐阅读
- ios - UIAlertController 不适用于 Rx-Single
- tensorflow - Tensorflow:tflite 文件是否包含有关模型架构的数据?(图形?)
- r - 绘制排名数据
- android - 有没有办法将 Flow 传递给 Room DAO Query 方法?
- elasticsearch - 在 Elasticsearch 中聚合嵌套数据数组
- git - git ident ID -- 如何获取匹配文件的版本?
- python - 防止 python subprocess.Popen() 启动另一个进程
- javascript - 隐藏/取消隐藏数百个 DOM 元素的最佳方法:更改 STYLE 或 CLASS?
- php - 使用 MySQL 和 PHP 查询(带括号)根据两个表中的值匹配输出我想要的 24 行 html 数据
- lua - 点击检测器事件不起作用