Hello community i'm new to angular and i'm trying to make a pagination component with logic, at this point i'm successfully getting the correct array in the console but in the view it is not changing.
i'm able to move through pages correctly only the pagination component itself is not changing. pagination view
the console i get when i navigate through the pages:
pagination.component.ts:25 (10) [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
pagination.component.ts:25 (10) [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
pagination.component.ts:25 (10) [3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
pagination.component.ts:25 (10) [4, 5, 6, 7, 8, 9, 10, 11, 12, 13]
pagination.component.ts:25 (10) [4, 5, 6, 7, 8, 9, 10, 11, 12, 13]
this is the function in the service that create the array that show correctly on console but not in the view.
initialPagination(totalPages: number) {
this.pagination = [];
this.numberOfPages = totalPages
if (this.numberOfPages <= 10) {
// less than 10 total pages so show all
this.startPage = 1;
this.endPage = this.numberOfPages;
} else {
// more than 10 total pages so calculate start and end pages
if (this.pageToShow <= 6) {
this.startPage = 1;
this.endPage = 10;
} else if (this.pageToShow + 4 >= this.numberOfPages) {
this.startPage = this.numberOfPages - 9;
this.endPage = this.numberOfPages;
} else {
this.startPage = this.pageToShow - 5;
this.endPage = this.pageToShow + 4;
}
}
// create an array of pages to ng-repeat in the pager control
for (let i = this.startPage; i < this.endPage + 1; i++) {
this.pagination.push(i)
}
return this.pagination
}
over here is the component itself
<ul class="pagination">
<li (click)="replacePage(pagination.pageToShow - 1)"><a>«</a></li>
<li (click)="replacePage(i)" [ngClass]="{active:pagination.pageToShow === i}"
*ngFor="let page of pager; let i = index"><a>{{i + 1}}</a></li>
<li (click)="replacePage(pagination.pageToShow + 1)"><a>»</a></li>
and here is the initialization of the pagination:
replacePage(page: number) {
if (page >= 0) {
if (page < this.numberOfPages) {
this.pagination.pageToShow = page;
this.pager = this.pagination.initialPagination(this.numberOfPages)
console.log(this.pager)
}
}
}
why iis the view not update but console is?