在 Angular 中使用 RxJS 的 Observable.combineList 时出现问题

Problem using Observable.combineList of RxJS in Angular

我想使用 typscript 函数必须要 Oberservable 同步。

首先我有一个服务,它给我 Oberservable 作为 return。

  public updatePlayers(players: Player[]): Observable<any>{
    return this.http.post(this.REST_URI + "player/updateplayers", players).pipe(
      tap(_tap => console.log("Update Players. " + _tap)),
      catchError(this.handleError)
    )
  }

比起我想使用 Observable.combineList 等待展位功能完成更新的功能。

OnSubmit(){

   let updateAllPlayers = combineLatest(this.restApi.updatePlayers(this.allPlayerTeam1), this.restApi.updatePlayers(this.allPlayerTeam1));
    updateAllPlayers.subscribe((teamxx1, teamxx2) => {
      this.router.navigate(['statsRecordGrid', this.team1.id, this.team2.id]);
    }, (e) => {
      console.error("Players not updated");
    });

}

....
}

我收到这个错误:

ERROR in players/players.component.ts(91,22): error TS2339: Property 'subscribe' does not exist on type 'OperatorFunction<{}, [{}, any, any]>'.

我不明白,因为如果我也用定时器做 RxJs 的例子,我会遇到同样的问题。

您导入了 lettable 运算符而不是函数。将 combineLatest 的导入更新为:

import { combineLatest } from 'rxjs';