Skip to content

[Tabs] Data binding that references the isActive property of a MatTab results in an ExpressionChangedAfterItHasBeenCheckedError #12197

@rachelrosengoogle

Description

@rachelrosengoogle

Bug, feature request, or proposal:

Bug: Data binding that references the isActive property of a MatTab results in an ExpressionChangedAfterItHasBeenCheckedError on the initial load of the app, and every time one navigates to or away from the tab for which the value is being used.

What are the steps to reproduce?

Here's a stackblitz that reproduces the issue:
https://angular-issue-tabs-expressionchangedafterithasbeenchecked.stackblitz.io

The error appears on the initial load and when switching tabs.

To repro you need a mat-tab-group with two or more tabs, and another component which has a property referencing the isActive property of one of the tabs:

<mat-tab-group>
<mat-tab #firstTab [label]="'Tab 1'">
<div class="content"></div>
</mat-tab>
<mat-tab [label]="'Tab 2'">
<div class="content"></div>
</mat-tab>
</mat-tab-group>

<foo-component [myProperty]="firstTab.isActive"></foo-component>

This results in the error: "Error: ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked. Previous value: 'myProperty: false'. Current value: 'myProperty: true'"

This initial error can be fixed by waiting for the MatTabGroup to be initialized before binding to myProperty, but the error also happens when navigating between tabs.

Metadata

Metadata

Assignees

Labels

GThis is is related to a Google internal issueP3An issue that is relevant to core functions, but does not impede progress. Important, but not urgent

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions