Ngx-bootstrap: Setting currentPage in Pagination gives "Expression has changed after it was checked" exception.

Created on 19 Aug 2016  Â·  12Comments  Â·  Source: valor-software/ngx-bootstrap

Hello! At first sorry for my terrible english ;)
I have problem with setting current page in Pagination component. When i set currentPage like:
private currentPage: number = 4; In my component class i have an error:

ORIGINAL EXCEPTION: Expression has changed after it was checked. Previous value: '4'. Current value: '1'

Is any 'dirty' fix for doing this now?

comp(pagination)

Most helpful comment

Import the following:

import { ChangeDetectorRef } from '@angular/core';

Then try using changeDetectionRef.detectChanges();

That fixed it for me.

All 12 comments

Import the following:

import { ChangeDetectorRef } from '@angular/core';

Then try using changeDetectionRef.detectChanges();

That fixed it for me.

I will try but it smell like dirty workaround :(

it is not a workaround or bug, you just tell to app that it should detect changes

After using changeDetectionRef.detectChanges() pagination works.. but after page load any pagination tiles is checked (screen below)

noname

I set currentPage in component by SetPage method in ngOnInit like this.
this.getPostCount().then((post_count) => { this.totalItems = post_count.post_count; this.changeDetectionRef.detectChanges() if(this.currentFirstPage != 1){ this.setPage(this.currentFirstPage); }; });
No errors in console.

You need to manually set currentPage to 1, and then use two-way data binding and bind currentPage to ngModel of your pagination, like this: [(ngModel)]="currentPage". That way, first page will be checked when pagination is loaded.

Yes, when i set currentPage to 1 everything works just fine. But sometimes i need load with another page checked (for example user access link like. http://localhost:3000/posts/3 ). Then i got blank pagination like in picture.

I'm having this issue as well.

Same here...when i try to change the "currentPage" via a method called by numPages event, i get that error.

Due to an issue in angular2 repo that is a "feature" that only happens when in development mode...

Hi, so just to understand.... if this issue is closed does it mean its fixed?

Thanks!

Code related to this issue was removed, plus my reproduce sample doesn't throw issue any more.
So...

ok thank, updating to 1.1.16-3 solved it (from 1.1.16)

On Mon, Dec 26, 2016 at 3:16 PM, Dmitriy Shekhovtsov <
[email protected]> wrote:

Code related to this issue was removed, plus my reproduce sample doesn't
throw issue any more.
So...

—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/valor-software/ng2-bootstrap/issues/862#issuecomment-269210621,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AEBDMh7bruJ06Vu8oS60ycQqzZPCHk_pks5rL75JgaJpZM4Joa7Y
.

--
Aviram Gabay

Getting this issue now with Angular 9 upgrade (9.0.0 -Didn't get it with our Angular8 version)

Current NgxBootstrap version: "ngx-bootstrap": "5.3.2"

Wrapping the event fired by the numPages @Output in setTimeout(() => {...}); fixes the error, but it's not ideal...

Was this page helpful?
0 / 5 - 0 ratings

Related issues

PascalHonegger picture PascalHonegger  Â·  3Comments

juanitavollmering picture juanitavollmering  Â·  3Comments

tpiros picture tpiros  Â·  3Comments

MihaiHoriaPopescu picture MihaiHoriaPopescu  Â·  3Comments

Scooviese picture Scooviese  Â·  3Comments