Answer the question
In order to leave comments, you need to log in
How to avoid a network request with undefined parameters by default?
The task is to make the angular material paginator work with the material grid list and material cards. By clicking on the paginator buttons, a network request should be sent to the server with the necessary parameters.
Request example: https://www.rijksmuseum.nl/api/en/collection?key=H... ,
where p is the number of pages with the date, ps is the number of data per page.
In view the following code:
<mat-paginator
[length]='itemsLength'
[pageIndex]='pageIndex'
[pageSize]='pageSize'
[pageSizeOptions]='pageSizeOptions'
showFirstLastButtons
(page)='pageEvent = getServerData($event)'>
</mat-paginator>
public getServerData(event?: PageEvent) {
console.log('page Event: ', event);
this.networkService.getQuery('Rembrandt', event?.pageIndex, event?.pageSize)
.subscribe(response => {
this.dataSource = response[this.artObjects];
this.itemsLength = response[this.count];
if (!!event) {
this.pageIndex = event.pageIndex;
this.pageSize = event.pageSize;
}
});
return event;
}
if (!event) {
event.pageIndex = 0;
event.pageSize = 10;
}
Answer the question
In order to leave comments, you need to log in
const pageIndex = event?.pageIndex || 0;
const pageSize = event?.pageSize || 10;
this.networkService.getQuery('Rembrandt', pageIndex, pageSize)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question