【发布时间】:2020-01-09 11:48:16
【问题描述】:
我的代码是:
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(cliente) 是:
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
【问题讨论】:
-
听起来是对的。您可以附加
shareReplay(),并且多个订阅不应触发源 Observable。 -
我不希望每次在 creaClienti 中进行的调用都会再次启动管道。
-
管道重新开始是什么意思?你在哪里订阅这些 observables?
.subscribe或aync管道?
标签: angular request rxjs httpclient