bug(Tabs): ExpressionChangedAfterItHasBeenCheckedError when providing MatTabNavPanel to tabPanel input of mat-tab-nav-bar
- Vorherrschende Sprache
- TypeScript
- Sterne
- 25k
- Forks
- 6.8k
- Ø Merge
- 1 T. 8 Std.
- Gemergte PRs (30 T.)
- 91
Beschreibung
### 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
Beitragsleitfaden
Rechercherichtung
Beginne mit der StackBlitz-Reproduktion, insbesondere mit src/example/tab-nav-bar-basic-example.html und der Komponente TabNavBarBasicExample, und untersuche dann, wie MatTabNavPanel durch den Wrapper weitergereicht wird. Reproduziere den Fehler, indem du auf die Navigationselemente klickst, und vergleiche das Verhalten mit der dokumentierten optionalen tabPanel-Eingabe; abgeschlossen ist es, wenn der Konsolenfehler nicht mehr auftritt.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- angular, typescript
- Bereich
- frontend
- Issue-Typ
- Bug
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 35/100