Answer the question
In order to leave comments, you need to log in
Can I make requests through a loop in http.get - Angular?
The situation is this, there is a list of people (let’s say I don’t know their number), 10 people are displayed on each page and there is a link to the next page, and so on until the last page, the last link is null.
How can I set a condition that while the reference is not null - make a request, if it is null, then stop and output somewhere (or some other way, smarter).
Now I just looked at how many there are in total, counted in my mind, created an array of these requests and made a request through forkJoin and displayed the result, but I'm sure that it can be done better. I couldn't find anything useful on the internet.
const queryPeople = [
this.http.get(`page=1`),
this.http.get(`page=2`)
this.http.get(`page=3`)
this.http.get(`page=4`)
this.http.get(`page=5`)
this.http.get(`page=6`)
]
forkJoin(queryPeople ).subscribe(result => console.log(result))
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question