bug(Tabs): ExpressionChangedAfterItHasBeenCheckedError when providing MatTabNavPanel to tabPanel input of mat-tab-nav-bar
- Dominant language
- TypeScript
- Stars
- 25k
- Forks
- 6.8k
- Avg merge
- 1d 8h
- Merged PRs (30d)
- 91
Description
### Is this a regression?
- [X] 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 https://github.com/angular/components/issues/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
Contributor guide
Research direction
Start with the StackBlitz reproduction, especially src/example/tab-nav-bar-basic-example.html and the TabNavBarBasicExample component, then inspect how MatTabNavPanel is passed through the wrapper. Reproduce the error by clicking the nav items and compare the behavior with the documented optional tabPanel input; done means the console error no longer occurs.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- angular, typescript
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100