Javascript RxJs合并http请求

Javascript RxJs合并http请求,javascript,angular,typescript,rxjs,Javascript,Angular,Typescript,Rxjs,我试图在rxjs帮助中合并两个HTTP请求以合并请求,但是第二个请求的参数(accountId、userId)在第一个请求的响应中 a = http.get<any>(...); b = http.get<any>(... + '/' + accountId + '/' + userId}) concat(a, b).subscribe(res => {}); a=http.get(…); b=http.get(…++'/'+accountId++'/'+us

我试图在rxjs帮助中合并两个HTTP请求以合并请求,但是第二个请求的参数(accountId、userId)在第一个请求的响应中

a = http.get<any>(...);
b = http.get<any>(... +  '/' + accountId + '/' + userId})

concat(a, b).subscribe(res => {});
a=http.get(…);
b=http.get(…++'/'+accountId++'/'+userId})
concat(a,b).subscribe(res=>{});
您可以使用合并多个订阅

forkJoin([a, b]).subscribe((res) => {
  // res[0] should be the response of `a`
  // res[1] should be the response of `b`
});

您可以使用mergeMap,因为您说过accountId和userId在第一个api请求的响应中

a.pipe(
 mergeMap(data => b(data.accountId,data.userId))
).subscribe(response => console.log(response));
你应该把b定义为返回可观测值的东西

b(accountId userId): Observable<any> {
 return http.get<any>(... +  '/' + accountId + '/' + userId)
}
b(accountId userId):可观察{
返回http.get(…++'/'+accountId++'/'+userId)
}

您只需通过aResponse将数据向下传递即可

a = http.get<any>(...);
b = http.get<any>(... +  '/' + accountId + '/' + userId})
const getBFromA$ = a.pipe(
    switchMap((aResponse) => {
        const accountId = aResponse.accountId;
        const userId = aResponse.userId;
        return http.get<any>(... +  '/' + accountId + '/' + userId})
    }).subscribe((bResponseOnly) => { // do something if you want to })
a=http.get(…);
b=http.get(…++'/'+accountId++'/'+userId})
const getBFromA$=a.pipe(
开关映射((响应)=>{
const accountId=aResponse.accountId;
const userId=aResponse.userId;
返回http.get(…++'/'+accountId++'/'+userId})
}).subscribe((bResponseOnly)=>{//如果您想做某事})

您使用的是哪个版本的rxjs?5还是6?@pindev版本6