订阅 combineLatest 中的所有 observable
Subscribe to all observables in a combineLatest
在我的代码中,我打开了一个 matDialog
允许 XLSX 提取。
打开此 matDialog
时,数据会加载到 ngOnInit()
,这可能需要一些时间。
这就是为什么我使用 combineLatest()
和 filter()
允许我等待三个查询的结果以允许提取。
我现在想添加一个 mat-progress-bar determinate
以查看提取的位置。
为此,我希望能够根据收到的每个结果修改我的变量 progress
。
所以我在每个请求上使用 map(result => {this.progress = this.progress + 30;}
来增加进度。
它有效,但破坏了我的 combineLatest()
。进度停在90%,我找不到解决方案。
代码:
this.subscriptions$.add(combineLatest([
this.storeWallets.loadInvoiceExtractionProduct(this.selectedWallet).pipe(
//map(result => { this.progress = this.progress + 30; }),
catchError(err => {
console.error(err.message);
return of(err);
})
),
this.storeWallets.loadInvoiceExtractionSupport(this.selectedWallet).pipe(
//map(result => { this.progress = this.progress + 30; }),
catchError(err => {
console.error(err.message);
return of(err);
})
),
this.storeWallets.loadInvoiceExtractionTraining(this.selectedWallet).pipe(
//map(result => { this.progress = this.progress + 30; }),
catchError(err => {
console.error(err.message);
return of(err);
})
),
]).pipe(
filter(results => results.every(res => !!res))
).subscribe(results => {
//this.progress = 100;
document.body.style.cursor = "default";
this.waitExtraction = false;
})
);
感谢您的帮助。
这一行:
map(result => { this.progress = this.progress + 30; }),
将获取每个结果和 return undefined,因为没有 return 语句(因此 filter
将过滤掉结果,并且订阅者不会是 运行)。将 map
替换为 tap
运算符,它应该可以工作。
在我的代码中,我打开了一个 matDialog
允许 XLSX 提取。
打开此 matDialog
时,数据会加载到 ngOnInit()
,这可能需要一些时间。
这就是为什么我使用 combineLatest()
和 filter()
允许我等待三个查询的结果以允许提取。
我现在想添加一个 mat-progress-bar determinate
以查看提取的位置。
为此,我希望能够根据收到的每个结果修改我的变量 progress
。
所以我在每个请求上使用 map(result => {this.progress = this.progress + 30;}
来增加进度。
它有效,但破坏了我的 combineLatest()
。进度停在90%,我找不到解决方案。
代码:
this.subscriptions$.add(combineLatest([
this.storeWallets.loadInvoiceExtractionProduct(this.selectedWallet).pipe(
//map(result => { this.progress = this.progress + 30; }),
catchError(err => {
console.error(err.message);
return of(err);
})
),
this.storeWallets.loadInvoiceExtractionSupport(this.selectedWallet).pipe(
//map(result => { this.progress = this.progress + 30; }),
catchError(err => {
console.error(err.message);
return of(err);
})
),
this.storeWallets.loadInvoiceExtractionTraining(this.selectedWallet).pipe(
//map(result => { this.progress = this.progress + 30; }),
catchError(err => {
console.error(err.message);
return of(err);
})
),
]).pipe(
filter(results => results.every(res => !!res))
).subscribe(results => {
//this.progress = 100;
document.body.style.cursor = "default";
this.waitExtraction = false;
})
);
感谢您的帮助。
这一行:
map(result => { this.progress = this.progress + 30; }),
将获取每个结果和 return undefined,因为没有 return 语句(因此 filter
将过滤掉结果,并且订阅者不会是 运行)。将 map
替换为 tap
运算符,它应该可以工作。