【发布时间】:2021-02-04 04:05:15
【问题描述】:
在我的代码中,我有一个按钮,可以浏览数据列表并为每个数据打开一个mat-dialog。
不幸的是,在循环过程中,所有mat-dialogs 都打开了。
我希望通过使用 dialogRef.afterClosed() 方法,根据结果 (true) 下一个 mat-dialog 打开或 (false) 循环结束。
openDialog(): void {
this.data.forEach(data => {
const dialogRef = this.dialog.open(DialogOverviewExampleDialog, {
disableClose: true
});
dialogRef.componentInstance.data = data;
dialogRef.afterClosed().subscribe(result => {
if (result) {
// open next mat-dialog
} else {
// stop loop
}
});
});
}
<div mat-dialog-actions>
<button mat-button (click)="_dialogRef.close(true)">Ok</button>
<button mat-button (click)="_dialogRef.close(false)">Cancel</button>
</div>
我该怎么做?我不知道该怎么做。
感谢您的帮助。
【问题讨论】:
标签: angular typescript rxjs angular-material mat-dialog