我想使用'HttpClient'进行多次通话。我以前与axios一起使用的相似之处。
在Vue中使用axios:
return axios.all([ axios.get('/friends/name'), axios.get('/family/name'), axios.get('/collegue/name'), ])
尝试使用角度:
return this.http.all([ this.http.get('/friends/name'), this.http.get('/family/name'), this.http.get('/collegue/name'), ])
错误TS2339:类型'HttpClient'上不存在属性'all'
我想使用'HttpClient'进行多次通话。我曾经与axios一起使用的类似工具。在Vue中使用axios:返回axios.all([axios.get('/ friends / name'),axios.get('/ ...
您必须使用forkJoin
运算符并按如下所示订阅数据
[使用HttpClient
发出请求时,它将返回一个rxjs Observable,您必须订阅该rxjs Observable才能发出请求。您应该根据使用情况,从rxjs中研究these运算符之一。
尝试使用forkJoin