Nivesh
Nivesh

Reputation: 1

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

<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.

Upvotes: -2

Views: 711

Answers (1)

Nivesh
Nivesh

Reputation: 1

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>`

Upvotes: 0

Related Questions