私は3つのHTTPリクエストを作り、それぞれのリクエストは他のリクエストに依存しています。現在、私は成功の次のリクエストをしていますが、それは非効率です。私はいくつかの研究を行なったし、私はflatmap
を使用すると仮定だが、私が試したいくつかの方法は、API3つのHTTPリクエストを正しくフラットマップする方法
にHTTPリクエストを行ういけない。これは、私が試したものであることがわかったが、それは何も
を返しませんreturn this.info.getLastRecord(this.station)
.map((res: any) => res.json()
.flatMap((info: any) => {
return this.info.getQueue(this.lastID)
.map((res: any) => {
console.log(res.json());
});
}));
このdoesntの仕事のどちらか
return this.info.getLastRecord(this.station)
.map((res: any) => res.json()
.flatMap((res: any) => {
return this.info.getQueue(this.lastID)
.map((res: any) => {
console.log(res);
});
}));
これは私が現在のコール
this.getInfoService.getLastRecord(this.station)
.subscribe(
(info) => {
console.log("res", info);
},
(error: Response) => console.log(error),
() => this.getQueue()
);
getQueue() {
this.info.getQueue(this.lastID)
.subscribe(
(info) => {
console.log("getQueue", info);
},
(error: Response) => console.log(error),
() => this.gHTDG())
}
getHookTypeDieGroup() {
this.info.getHookTypeDieGroup(this.profileCode)
.subscribe(
(info) => {
console.log("GHTDG", info);
},
(error: Response) => console.log(error)
);
}
を作ってるんですか
info.service.ts
getLastRecord(station: string): any {
return this.http.get('http://API.app/getLastRecord/' + station)
.map(
(response: Response) => {
return response.json().info;
},
).share();
}
getQueue(lastID: number): any {
return this.http.get('http://API.app/getQueue/' + lastID)
.map(
(response: Response) => {
return response.json().info;
}
)
.share();
}
gHTDG(pCode: string): any {
return this.http.get('http://API.app/getHTDG/' + pCode)
.map(
(response: Response) => {
return response.json().info;
}
).share();
}
をチェック。私はそれがあなたが望むように働いていると思う。 –