ExpressionChangedAfterItHasBeenCheckedError when matSortActive and MatPaginator are both used
See original GitHub issueBug, feature request, or proposal:
Bug
What is the expected behavior?
Using MatTable
with MatPaginator
, MatSort
and a default sort configured with matSortActive
should work without error.
What is the current behavior?
- when using
MatTable
withMatPaginator
,MatSort
and a default sort configured withmatSortActive
, - if all the elements of the datasource are not shown in the first page,
- then the error
ExpressionChangedAfterItHasBeenCheckedError
is produced without good reason.
What are the steps to reproduce?
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:
- disabling the default sort order (
matSortActive
) or the paginator binding inngAfterViewInit
makes the error disappear. - setting the paginator to show more items than available also makes the error disappear.
Which versions of Angular, Material, OS, TypeScript, browsers are affected?
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
Issue Analytics
- State:
- Created 6 years ago
- Comments:8 (1 by maintainers)
Top Results From Across the Web
Stack Overflow
Angular 9 mat-table and ExpressionChangedAfterItHasBeenCheckedError · This kind of issues are usually solved by moving the code to a more ...
Read more >Angular Material Data Table: A Complete Example
A complete example of an Angular Material Data Table with server-side pagination, sorting, filtering, as well as a loading indicator.
Read more >UNPKG - @angular/material
n */\n get paginator(): MatPaginator | null { return this. ... slide-toggle-required-validator';\n\n/** This module is used by both original and MDC-based ...
Read more >Angular material table with initial sort header - Medium
Sort header : The matSort and mat-sort-header are used, respectively, to add sorting ... matSortActive: The id of the most recently sorted MatSortable....
Read more >Multiple mat-table in same component with matSort & mat ...
Similarly we need to add mat-paginator as well. <table mat-table [dataSource]="dataSource" class="mat-elevation-z8" ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
It’s valid to use
ngOnInit
in v6 due to some changes in #10593@WizardPC actually, to fix the problem, from my original stackblitz, you just need to set the
sort
before thepaginator
inngAfterViewInit
.Note also that the data must be set in
ngOnChanges
, but that’s not a problem here.