1 回答

TA貢獻1865條經(jīng)驗 獲得超7個贊
您需要利用flatMap運算符在上一個請求完成后調(diào)用一個請求:
this.service.getUserInterests().flatMap(
(interests) => {
let params: URLSearchParams = new URLSearchParams();
params.set('access_token', localStorage.getItem('access_token'));
return this.http.get('http://localhost:8080/user/selections', {
search: params
}).map((res: Response) => res.json());
}
);
訂閱此數(shù)據(jù)流時,您只會收到上一個請求的結(jié)果。
您可以使用該Observable.forkJoin方法返回兩者。這是一個示例:
var obs = this.service.getUserInterests().flatMap(
(interests) => {
return Observable.forkJoin([
Observable.of(interests),
this.service.getUserSelections()
]);
}
);
obs.subscribe(
(result) => {
var interests = result[0];
var selections = result[1];
}
);
添加回答
舉報