我有以下代码:
dialog.afterClosed()
.pipe(
filter((result) => result),
mergeMap((result) => this.unitService.importPack(result.file))
)
.subscribe((result) => {
console.log(result); // I need the result of both, not only the mergeMap result
this.updateStateAfterUpload(result.file, 'imported');
});这里的问题是,我订阅中的result是在mergeMap操作符中返回的observable的结果,但我实际上需要使用这两个结果-从我的afterClosed() observable返回的结果和由mergeMap操作符返回的结果。
如何在订阅中返回这两个观察值的结果?
发布于 2019-03-06 21:25:00
dialog.afterClosed().pipe(
mergeMap(result1 => this.unitService.importPack(result.file).pipe(
map(result2 => ({ result1, result2 }))
))
).subscribe(({ result1, result2 }) => { ... });映射第二个请求的结果以返回您想要的结果。在这里,我返回一个{ result1: any, result2: any }类型的对象
https://stackoverflow.com/questions/55024091
复制相似问题