Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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