ngx-bootstrap icon indicating copy to clipboard operation
ngx-bootstrap copied to clipboard

One way binding for current page

Open bohrasankalp opened this issue 1 year ago • 1 comments

I'm trying to update currentPage using store management, but it ends up with Cannot assign to read only property 'currentPage' of object '[object Object]'.

<ng-container *ngIf="pagination$ | async as paginate">
	<pagination
		[(ngModel)]="paginate.currentPage"
		[boundaryLinks]="true"
		[itemsPerPage]="paginate.perPageRecords"
		[maxSize]="paginate.maxPaginationSize"
		[rotate]="true"
		[totalItems]="paginate.totalRecords"
		(pageChanged)="pageChanged($event)"></pagination>
</ng-container>

If I remove [(ngModel)]="paginate.currentPage" this works well if start with first page, but won't work in condition if I jump to intermediate page eg ?page=12.

Any work around for this?

bohrasankalp avatar Dec 25 '23 11:12 bohrasankalp

Any updates?

bohrasankalp avatar Jan 26 '24 13:01 bohrasankalp

You are using 2 way binding on ngrx value which is readonly and can only be changed through the state update. In your case you should change it to

<ng-container *ngIf="pagination$ | async as paginate">
	<pagination
		[ngModel]="paginate.currentPage"
		[boundaryLinks]="true"
		[itemsPerPage]="paginate.perPageRecords"
		[maxSize]="paginate.maxPaginationSize"
		[rotate]="true"
		[totalItems]="paginate.totalRecords"
		(pageChanged)="pageChanged($event)"></pagination>
</ng-container>

lexasq avatar Jul 11 '24 09:07 lexasq