bug(Tabs): ExpressionChangedAfterItHasBeenCheckedError when providing MatTabNavPanel to tabPanel input of mat-tab-nav-bar
- Lingua principale
- TypeScript
- Stelle
- 25k
- Fork
- 6.8k
- Merge medio
- 1g 8h
- PR unite (30g)
- 91
Descrizione
### 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
Guida per i contributori
Apri la guida per i contributori
Direzione di ricerca
Inizia con la riproduzione StackBlitz, in particolare con src/example/tab-nav-bar-basic-example.html e il componente TabNavBarBasicExample, poi esamina come MatTabNavPanel viene passato attraverso il wrapper. Riproduci l'errore facendo clic sugli elementi di navigazione e confronta il comportamento con l'input tabPanel opzionale documentato; è completato quando l'errore nella console non si verifica più.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- angular, typescript
- Ambito
- frontend
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 35/100