我正在开展一个角度cli项目,我有一个方法可以评估多个https请求。“
this.files = this.http.get("assets/L10n/customer.json")
.map(res => res.json())
.subscribe(data => console.log(data));
}
this.files2 = this.http.get("assets/L10n/customer2.json")
.map(res => res.json())
.subscribe(data => console.log(data));
}
我想将this.files和this.files2作为数组返回。感谢任何帮助。
答案 0 :(得分:0)
您可以使用forkJoin
:
let first = this.http.get("assets/L10n/customer.json")
.map(res => res.json());
let second = this.http.get("assets/L10n/customer2.json")
.map(res => res.json());
Observable.forkJoin(first, second).subscribe(
(resultArray) => {
// `resultArray` is a combined array of first and second results
console.log(resultArray);
}
)