bug(Tabs): ExpressionChangedAfterItHasBeenCheckedError when providing MatTabNavPanel to tabPanel input of mat-tab-nav-bar
- Lenguaje dominante
- TypeScript
- Estrellas
- 25k
- Forks
- 6.8k
- Merge medio
- 1 d 8 h
- PR fusionados (30 d)
- 91
Descripción
### 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
Guía de contribución
Línea de trabajo
Empieza con la reproducción de StackBlitz, especialmente con src/example/tab-nav-bar-basic-example.html y el componente TabNavBarBasicExample, y luego inspecciona cómo se pasa MatTabNavPanel a través del wrapper. Reproduce el error haciendo clic en los elementos de navegación y compara el comportamiento con la entrada opcional tabPanel documentada; se considera terminado cuando el error de consola ya no se produce.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- angular, typescript
- Área
- frontend
- Tipo de issue
- Error
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 35/100