Using Angular 4. I have a paging.component
that gets the page number and pageSize from it's parent component (after it gets data).
The paging.component
will look for changes to the @Input
's using the OnChanges
life-cycle hook.
The paging.component
also has a <select>
input where you can change the pageSize.
During the OnInit
phase, the <select>
gets set to the pageSize passed in from the parent component.
If you change the pageSize with the <select>
, it all works ok, but I sometimes also want to change the pageSize from the parent component to a different value (like the original value).
When I change the pageSize from the parent component, however, it does not change the <select>
input. (Even though everything else seems to work correctly).
I tried adding the following code to the ngOnChanges
method:
if (this.pageSizeFG) {
this.pageSizeCtrl.setValue(this.pagesize);
}
However, this gives errors:
ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked. Previous value: 'false'. Current value: 'true'.
The paging also seems to keep reseting itself to page 1 if I try to go to a different page.
I've looked into some of the other life-cycle hooks, ChangeDetectorRef
, and ngZone
, but those seem to make the problem worse.
I have created a plnkr here that demonstrates the error.
If you go to the paging.component.ts
and comment out the line with this.pageSizeCtrl.setValue(this.pagesize);
, then everything works fine EXCEPT the <select>
does not update.