Z
Z
Zombie426792020-03-01 23:32:52
JavaScript
Zombie42679, 2020-03-01 23:32:52

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

2 answer(s)
I
IDONTSUDO, 2020-03-02
@IDONTSUDO

through PromiseAll it can be done

A
Anton Shvets, 2020-03-02
@Xuxicheta

https://rxviz.com/v/qJw4a1v8

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question