在我的Angular 2应用程序中,我有后端服务,如下所示.
getUserInterests() {
return this.http.get('http://localhost:8080/test/selections').map((res: Response) => res.json());
}
Run Code Online (Sandbox Code Playgroud)
在调用此服务后,我想在上一个服务成功之前调用另一个服务.
第二次服务
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());
Run Code Online (Sandbox Code Playgroud)
这两个服务分别返回两个JSON数组.然后我需要用这两个数组进行一些登录.
EDITED
service.ts
getUserInterests() {
return this.http.get('http://localhost:8080/test/selections').map((res: Response) => res.json());
}
getSavedSelections() {
let params: URLSearchParams = new URLSearchParams();
params.set('access_token', localStorage.getItem('access_token'));
return this.http.get('http://localhost:8080/interest/user/selections', { search: params }).map((res: Response) => res.json());
}
getSelectionList() {
var obs = this.getUserInterests().flatMap(
(interests) => {
return Observable.forkJoin([
Observable.of(interests),
this.getSavedSelections()
]);
}
);
return obs;
}
Run Code Online (Sandbox Code Playgroud)
然后我在我的其他ts文件中使用以下来调用该服务. …