Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
rachelrosengoogle opened this issue Jul 13, 2018 · 2 comments · Fixed by #12206
Assignees
Labels
G This is is related to a Google internal issue P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent

Comments

@rachelrosengoogle
Copy link

rachelrosengoogle commented Jul 13, 2018

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.

@crisbeto crisbeto self-assigned this Jul 14, 2018
crisbeto added a commit to crisbeto/material2 that referenced this issue Jul 14, 2018
* Fixes a "changed after checked" error being thrown if the consumer is using the `isActive` property of a tab somewhere in the view.
* Reworks the `MatTab` to only have one `stateChanges` subject rather than one per property.

Fixes angular#12197.
@crisbeto crisbeto added P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent has pr labels Jul 14, 2018
@josephperrott josephperrott added the G This is is related to a Google internal issue label Jul 16, 2018
@rachelrosengoogle
Copy link
Author

Hi. Thanks for making the PR! I was wondering if there is any update on this? This is blocking us from writing tests for our components with tabs, since the ExpressionChangedAfterItHasBeenCheckedError causes tests to fail. Happy to help in any way I can.

mmalerba pushed a commit that referenced this issue Aug 13, 2018
…12206)

* Fixes a "changed after checked" error being thrown if the consumer is using the `isActive` property of a tab somewhere in the view.
* Reworks the `MatTab` to only have one `stateChanges` subject rather than one per property.

Fixes #12197.
mmalerba pushed a commit that referenced this issue Aug 20, 2018
…12206)

* Fixes a "changed after checked" error being thrown if the consumer is using the `isActive` property of a tab somewhere in the view.
* Reworks the `MatTab` to only have one `stateChanges` subject rather than one per property.

Fixes #12197.
@angular-automatic-lock-bot
Copy link

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.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 9, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
G This is is related to a Google internal issue P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants