【发布时间】:2021-11-29 22:46:21
【问题描述】:
之前,我问过一个关于用等待子请求返回嵌套httprequest的问题。
https://stackoverflow.com/questions/69308614/angular-map-wait-observable-to-complete[Angularmap 等待 Observable 完成]1
我对它做了一些更改,但它抛出了错误
错误:您在预期流的位置提供了“未定义”。您可以提供 Observable、Promise、Array 或 Iterable。
这是我的更新代码
test2(): Observable<Student[]> {
return this.test1().pipe(
mergeMap((result) => {
if (!result) {
return of(result);
}
return forkJoin(
result.map((rr) => {
if (rr.age === 1) {
rr.age = rr.age * 10;
return of(rr);
} else {
this.client
.get('https://api.coindesk.com/v1/bpi/currentprice.json')
.pipe(
map((res) => {
console.log(res);
rr.age = rr.age * 10000;
return rr;
})
);
}
})
).pipe(
map((paths) => {
console.log('w');
console.log(paths);
return paths;
// return result.map((e, index) => ({
// age: paths[index],
// }));
})
);
})
);
}
【问题讨论】:
标签: angular rxjs observable