代码之家  ›  专栏  ›  技术社区  ›  user824624

是否在8月2日同时返回多个服务数据?

  •  1
  • user824624  · 技术社区  · 8 年前

    我正在研究angular 4,目前使用相同的web服务多次加载不同的数据,并同时将所有多个数据返回到组件。

      loadTemplate(token):  Observable<any>{
        return this.http.get("/assets/guide/"+token+"_"+type+".html").map(res =>res.text());
      }
    

    如何将这些http服务打包成一个函数?

    1 回复  |  直到 8 年前
        1
  •  2
  •   Sajeetharan    8 年前

    您可以使用 .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 => {
    
    });
    
    推荐文章