Angular 8 RXJS - 按顺序进行多个 HTTP 调用

Angular 8 RXJS - Make multiple HTTP calls sequentially

我的代码是:

return this.creaClienti(cliente)
      .pipe(
        tap(res => console.log('Cliente ->', res)),
        concatMap(res => this.creaIntolleranza(intolleranza)),
        tap(res => console.log('Intolleranza ->', res)),
        concatMap(res => this.creaSpaziUtilizzati(utilizzoSpazi)),
        tap(res => console.log('Utilizzo spazi ->', res)),
        concatMap(res => this.creaEvento(evento))
      );
  }

但是this.creaClienti(客户)是:

 creaClienti(clienti: any[]): Observable<any> {
    return from(clienti).pipe(
      concatMap(cliente => <Observable<any>>this.http.post(environment.baseUrl + 'api/json/node/cliente', cliente, this.httpOptions))
    );
  }

问题是每次包含的调用结束时,管道都会重新启动...

我需要按顺序运行多个调用列表,concatMap中的所有函数实际上类似于creaClienti

我想您希望所有函数(this.creaClientithis.creaIntolleranzathis.creaSpaziUtilizzatithis.creaEvento(evento))仅在所有内部 http 调用完成时发出一次。

如果creaClienti 应该只在所有内部调用完成后发出,您可以添加 lasttoArray,具体取决于您想要的输出。

creaClienti(clienti: any[]): Observable<any> {
  return from(clienti).pipe(
    concatMap(cliente => <Observable<any>>this.http.post(environment.baseUrl + 'api/json/node/cliente', cliente, this.httpOptions)),
    last() // only emit the last http response
    // or toArray() // emit all http response in an array when the last one completed
  );
}