question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ExpressionChangedAfterItHasBeenCheckedError when matSortActive and MatPaginator are both used

See original GitHub issue

Bug, 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 with MatPaginator, MatSort and a default sort configured with matSortActive,
  • 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 in ngAfterViewInit 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:closed
  • Created 6 years ago
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
andrewseguincommented, Apr 23, 2018

It’s valid to use ngOnInit in v6 due to some changes in #10593

2reactions
victornoelcommented, Mar 13, 2018

@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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found