Angular 在所有可观测数据完成后订阅最终可观测数据?
我这里有一个逻辑,它创建了许多可观察的对象,并在每个对象完成后执行回调Angular 在所有可观测数据完成后订阅最终可观测数据?,angular,angular9,angular10,rxjs-observables,Angular,Angular9,Angular10,Rxjs Observables,我这里有一个逻辑,它创建了许多可观察的对象,并在每个对象完成后执行回调 from(rows).pipe( concatMap(row => this.uploadItem(row)) ).subscribe(response => { this.currentRowNode.data.uploadStatus = UploadStatus.Success; this.currentRowNode.data.cmsRowId = response.respons
from(rows).pipe(
concatMap(row => this.uploadItem(row))
).subscribe(response => {
this.currentRowNode.data.uploadStatus = UploadStatus.Success;
this.currentRowNode.data.cmsRowId = response.responsePayload.cmsRowId
this.currentRowNode.setData(this.currentRowNode.data);
});
currentRowNode: RowNode;
uploadItem(rowNode: RowNode): Observable<any> {
this.currentRowNode = rowNode;
rowNode.data.uploadStatus = UploadStatus.Uploading;
rowNode.updateData(rowNode.data);
return this.importService.uploadItem(rowNode.data)
}
来自(行)。管道(
concatMap(行=>this.uploadItem(行))
).订阅(响应=>{
this.currentRowNode.data.uploadStatus=uploadStatus.Success;
this.currentRowNode.data.cmsRowId=response.responsePayload.cmsRowId
this.currentRowNode.setData(this.currentRowNode.data);
});
currentRowNode:RowNode;
uploadItem(rowNode:rowNode):可观察{
this.currentRowNode=rowNode;
rowNode.data.uploadStatus=uploadStatus.Uploading;
rowNode.updateData(rowNode.data);
返回此.importService.uploadItem(rowNode.data)
}
我的问题是,我希望能够订阅一些东西,告诉我,uploadItem
已为每个行调用了
那会去哪里?你可以创建一个这样的可观察对象
const final$ = of("completed");
使用rxjsconcat操作符,将其与现有的可观测值进行concat,如下所示
const myobs$ = from(rows).pipe(concatMap(row => this.uploadItem(row)));
concat(myobs$, final$).subscribe(response=>{
//your existing code here
if(response=="completed")
{
console.log('all observables completed');
}
});
在这里,我创建了一个