首页 > 解决方案 > 等待模态响应时冻结代码块

问题描述

这个想法是当用户处理某事并尝试运行一些敏感组件时,他需要确认密码。这样,我们就可以对用户进行身份验证。确认密码对话框如下所示:

在此处输入图像描述

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");

怎么做?感谢任何人。

标签: angulartypescriptapi

解决方案


推荐阅读