Skip to content

bug(Tabs): ExpressionChangedAfterItHasBeenCheckedError when providing MatTabNavPanel to tabPanel input of mat-tab-nav-bar #28379

Open
@muenchto

Description

@muenchto

Is this a regression?

  • Yes, this behavior used to work in the previous version

The previous version in which this bug was not present was

Angular Material pre-MDC

Description

mat-tab-nav-bar requires a reference to it's MatTabNavPanel via the tabPanel input. Documentation says this is optional but code makes it required as reported in #26270.

However, when the mat-tab-nav-bar is wrapped in some other component, e.g. an AppHeaderComponent, but the MatTabNavPanel is outside this component, we need to pass the reference to the MatTabNavPanel via Input into the wrapper component like AppHeaderComponent and then use it in the template. This is the only way I can think of, but it throws a ExpressionChangedAfterItHasBeenCheckedError (quite obvious for everyone who understand Angular's CD resolution algorithm really good, but hard to understand for everyone else), for example

ERROR Error: NG0100: ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked. Previous value for 'attr.aria-labelledby': 'mat-tab-link-4'. Current value: 'mat-tab-link-2'. Expression location: TabNavBarBasicExample component.

Reproduction

StackBlitz link: https://stackblitz.com/edit/udrwuw?file=src%2Fexample%2Ftab-nav-bar-basic-example.html
Steps to reproduce:

  1. Open developer console in browser
  2. Click around on the Nav Items
  3. Observe error in developer console

Expected Behavior

No error. I suggest simply making tabPanel optional like stated in Documentation, but of course would be nice to have a good solution to use mat-tab-nav-bar in a wrapper component

Actual Behavior

ExpressionChangedAfterItHasBeenCheckedError

Environment

  • Angular: 16+
  • CDK/Material: 16+ aka MDC
  • Browser(s): any
  • Operating System (e.g. Windows, macOS, Ubuntu): any

Metadata

Metadata

Assignees

No one assigned

    Labels

    P4A relatively minor issue that is not relevant to core functionsarea: material/tabs

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions