Remove Pagination Control for ngb-pagination if only 1 page exists

571 Views Asked by At
<ngb-pagination 
                  [(page)]="p"
                  [maxSize]="10"
                  [collectionSize]="totalDocs"
                  (pageChange)="pageChanged($event)"
                  [rotate]="true"
                  (itemsPerPage)="limit"
                  (currentPage)="currentPage">
</ngb-pagination>

I wanted to hide ngb pagination control unless there is more than 1 page on the screen, I couldn't find any easy answer for this so I figured out how to do it easily. thought I should share how I did it.

1

There are 1 best solutions below

0
Nivesh On

Declare variable for page count, e.g. totalPages = 1; on the corresponding component.ts file & use *ngIf to hide pagination as below.

`<ngb-pagination 
                  *ngIf="totalPages>1"
                  [(page)]="p"
                  [maxSize]="10"
                  [collectionSize]="totalDocs"
                  (pageChange)="pageChanged($event)"
                  [rotate]="true"
                  (itemsPerPage)="limit"
                  (currentPage)="currentPage">
</ngb-pagination>`