Bug
Using MatTable with MatPaginator, MatSort and a default sort configured with matSortActive should work without error.
MatTable with MatPaginator, MatSort and a default sort configured with matSortActive,ExpressionChangedAfterItHasBeenCheckedError is produced without good reason.https://stackblitz.com/edit/angular-material2-issue-cadz7g
On loading, the error ExpressionChangedAfterItHasBeenCheckedError is produced.
I suspect that it is the combination between the paginator not showing every elements and the default sort that triggers some kind of intermediary state where a cell changes after change detection has passed.
Also:
matSortActive) or the paginator binding in ngAfterViewInit makes the error disappear.Angular CLI: 1.7.3
Node: 6.9.5
OS: linux x64
Angular: 5.2.8
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router
@angular/cdk: 5.2.4
@angular/cli: 1.7.3
@angular/material: 5.2.4
@angular-devkit/build-optimizer: 0.3.2
@angular-devkit/core: 0.3.2
@angular-devkit/schematics: 0.3.2
@ngtools/json-schema: 1.2.0
@ngtools/webpack: 1.10.2
@schematics/angular: 0.3.2
@schematics/package-update: 0.3.2
typescript: 2.6.2
webpack: 3.11.0
I'm not sure but the result is here and not the error :
@WizardPC I'm surprised that sort is already bound when ngOnInit is called and before afterViewInit, but yes, it seems to work like this.
Let's wait for a comment from the devs to see if there is more to it :)
@victornoel yep !
It's just my logical reasoning. Not from coding point of view ^^
@WizardPC actually, to fix the problem, from my original stackblitz, you just need to set the sort before the paginator in ngAfterViewInit.
Note also that the data must be set in ngOnChanges, but that's not a problem here.
@victornoel good to know :)
It's valid to use ngOnInit in v6 due to some changes in #10593
Setting the dataSource in ngOnInitand setting paginator in ngAfterViewInitworks fine with M6. Setting paginator inside ngOnInitdid not work.
This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
_This action has been performed automatically by a bot._
Most helpful comment
It's valid to use
ngOnInitin v6 due to some changes in #10593