How to make automatic parameter on URL?

I’ve been request array from API and it only appears 20 array per page. Meanwhile, total results are thousands array.

This is the service.ts I’ve made.

getHome(){
let params: URLSearchParams = new URLSearchParams();
let headers = new Headers();
headers.append(‘Content-Type’, ‘application/vnd.api+json’);
headers.append(‘Accept’, ‘application/vnd.api+json’);

params.set("api_key","4285b6347f0429f60f6364ca644beab2");
params.set("page", "1" )


let options = new RequestOptions({
  headers: headers,
  search: params
});

return this.http.get(this.API+"movie/top_rated", options)
  .map(
  (res: Response) => {
    return res.json()
  })

}

I need to change the number at params.set("page", "1" ) automatically, when I use (doInfinite) to load more array from the next page. So how do I make it happen ?

Thanks a lot.

You could try something like this:

getHome() {
    return async function* () {
      let page = 1;
      while (true) {
        let search: URLSearchParams = new URLSearchParams();
        let headers = new Headers({
          'Content-Type': 'application/vnd.api+json',
          'Accept': 'application/vnd.api+json'
        });

        search.set('api_key', '4285b6347f0429f60f6364ca644beab2');
        search.set('page', '1');

        let options = new RequestOptions({ headers, search });

        const nextData = await this.http.get(this.API + "movie/top_rated", options)
          .map((res: Response) => res.json())
          .toPromise();
        yield nextData;
        page++;
      }
    }
  }

I hope it is correct that way. It is the first generator I write.