I am making an http.get request to an API to get data. The API uses pagination and contains 30 entries/page. It also provides information about next page and last page along with respective links (also prev page and first page when applicable) in the response header links.
The Link header includes pagination information:
<https://api.example.com/user?page=2>; rel="next",
<https://api.example.com/user?page=10>; rel="last"
The JSON object in response.body
[
{
userId: 1,
name: 'John',
created_at: "2015-10-13T03:10:43Z",
},
{
userId: 2,
name: 'Jane',
created_at: "2019-02-15T13:37:03Z",
}
....
]
I am using angular 6 and trying to accumulate the data by making subsequent http.get calls. I have tried to use array method push() for subsequent data. But the since the typeof resp.body is object it is not working.
userData: any[];
getData(url: string) {
this.http.get(url, {observe: 'response'});
.subscribe((resp) => {
this.userData.push(resp.body);
}
Error message: TypeError: Cannot read property 'push' of undefined
The userData should contain array of data received from http.get requests which is iterable.