我试图在我的angular 2组件中使用多个REST端点调用。问题是,我没有从他们中的任何人那里得到任何数据。我这样做是:
getData() {
myService.getDataA().subscribe(data => { this.dataA = data })
myService.getDataB().subscribe(data => { this.dataB = data })
myService.getDataC().subscribe(data => { this.dataC = data })
我的服务是:
getDataA() {
return this.http.get(MY_URL).map(data => data.json());
getDataB() {
return this.http.get(MY_URLB).map(data => data.json());
getDataC() {
return this.http.get(MY_URLC).map(data => data.json());
有没有办法如何等待所有异步任务完成然后显示模板?
谢谢
答案 0 :(得分:0)
答案 1 :(得分:0)
做这样的事情
Observable.forkJoin(getDataA(), getDataB(), getDataC()).subscribe(response => {
response[0] //contain getDataA response
response[1] //contain getDataB response
response[2] //contain getDataC response
}, e => { //get the errors });