This is my first question here, sorry if it isn't detailed enough.I am looking to make a dynamic amount of requests sequentially (could be a lot) to get data,I would need this data to be collected from each request and returned as a final observable at the end of the last request.I have attempted to use forkJoin to combine the requests, although, this does not make each request sequentially and then also concat, which emits and observable after each request. 解决方案 You want to:Make an arbitrary number of sequential HTTP requests (based on some array, I assume)Return an array of resultsI would use concat in conjunction with toArray here. concat will run the requests sequentially, and toArray will emit an array when all responses are available.// some dynamic arrayconst source = [ 1, 2, 3, 4, 5 ];const observables = source.map(x => this.http.get('some url'));concat( ...observables).pipe( toArray()).subscribe(responses => { console.log(responses); // array of results});DEMO: https://stackblitz.com/edit/angular-s1fdxj 这篇关于Angular 中连续 HTTP 请求的动态数量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-19 17:50