【问题标题】:Angular 6 Material - Await until Mat Dialog is closedAngular 6 Material - 等待 Mat 对话框关闭
【发布时间】:2019-04-16 10:53:02
【问题描述】:

我有一个要完成的操作列表,如果设置了布尔值 promptRequired,我会显示一个对话框并根据它的值执行一些操作。

这里的问题是for循环并行运行并且所有动作同时执行,但是我希望for循环同步运行并且循环必须等到对话框关闭。有解决办法吗?

async runActions() {
 for (const action of Actions) {
      if(action.promptRequired) {
      const dialogRef = this.promptDialog.open(PromptDialogComponent, {
        data: {action: action,
        },
      });
      // await dialogRef.afterClosed();
     }
    }

     const status =  await this.httpService.getRequest('runAction', action)
     // Do Some Action based on status
  }
 }
}

【问题讨论】:

标签: angular asynchronous async-await angular-material angular6


【解决方案1】:

你可以把afterClosed Observable 变成一个promise 并等待结果。示例:

async runActions() {
  for (const action of Actions) {
    if(action.promptRequired) {
      const dialogRef = this.promptDialog.open(PromptDialogComponent, {
        data: {action: action },
      });

      await dialogRef.afterClosed().toPromise();
    }
  }

  const status =  await this.httpService.getRequest('runAction', action)
  // Do Some Action based on status
}

【讨论】:

  • ngx-bootstrap 呢?我很坚持这一点。
  • 表示“afterClosed”不在订阅中
猜你喜欢
  • 2017-04-05
  • 1970-01-01
  • 2020-06-02
  • 2021-09-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多