我正在研究angular 4,目前使用相同的web服务多次加载不同的数据,并同时将所有多个数据返回到组件。
loadTemplate(token): Observable<any>{ return this.http.get("/assets/guide/"+token+"_"+type+".html").map(res =>res.text()); }
如何将这些http服务打包成一个函数?
您可以使用 .combineLatest
.combineLatest
const bothrequests= Observable.combineLatest( this.http.get('https://testdb1.com/.json').map((res: Response) => res.json()), this.http.get('https://testdb2.com/.json').map((res: Response) => res.json()) ) bothrequests.subscribe(latestValues => { });