打字稿中来自多个 api 的 MEAN SATCK angular2:get 数据

MEAN SATCK angular2:get data from multiple api in typescript

  1. 使用 angular2、nodejs、expressjs,mongodb。
  2. 我想要所有 api 到 return 数据并显示在 html 页上。
  3. 这是我的 .ts 文件代码。 enter image description here

    • 所有 apis 测试工作正常 returns 数据形式 mongodb.
    • 但首先 api return 数据并显示在 html 页面上。
    • 在这种情况下,countphones api 会返回数据,而其他两个不会。
    • 但是当第一个被评论时,第二个开始显示 html 上的数据 页。
    • 先到先得。
export class AppComponent  {

phone$ = http.get("...").map(r => r.json())
laptop$ = http.get("...").map(r => r.json())
television$ = http.get("...").map(r => r.json())

ngOnInit(){
    Observable
    .forkJoin(this.phone$, this.laptop$, this.television$)
    .subscribe(([phones, laptops, televisions])=>{
        this.phones = phones;
        this.laptios = laptops;
        this.televisions = televisions;
  });
}
}