Skip to content

Instantly share code, notes, and snippets.

@navanathjadhav
Created December 25, 2020 15:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save navanathjadhav/d9c740c61c792229f394dcadec63e77e to your computer and use it in GitHub Desktop.
Save navanathjadhav/d9c740c61c792229f394dcadec63e77e to your computer and use it in GitHub Desktop.
2. Added API call for fetching data
apiRoute: string = `http://localhost:4000/api/students`;
// Fetch new page data
next() {
this.getData(this.currentPageNumber + 1)
}
// Fetch previous page data
prev() {
this.getData(this.currentPageNumber - 1)
}
// Fetch data from API
getData(pageNo: any) {
this.currentPageNumber = Number(pageNo);
let finalPath = `${this.apiRoute}?pageNumber=${this.currentPageNumber}&recordsPerPage=5`;
this.http.get(finalPath).subscribe(
(response: any) => {
console.log('Total records count:', response.count)
console.log('Response data:', response.data)
},
(error) => {
console.log(error.message);
}
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment