angular / angular/components

bug(mat-select): mat-options not showing up on dynamically generated component

Abierto
#26,803 10 comentarios 0 reacciones 1 asignado Reclamado por @andrewseguin Ver en GitHub
area: material/select area: theming P3
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?

- [ ] Yes, this behavior used to work in the previous version

### The previous version in which this bug was not present was

_No response_

### Description

Hi, this is my first issue, so I hope everything is corrent.

I'm currently implementing some map popups (using leaflet, but I assume the issue would also appear for other map providers) in my app, using dynamically generated components as their content. Within that components, I have a mat-select, which is not displaying any options, as the title mentioned. When I click on it, the select field itself is focused and gets the correct classes, but the options overlay is not appearing.

My guess is, that something is wrong with the handling of the overlay in combination with dynamically generated components. When checking the DOM, I could see that the overlay container was not added to the body. Outside of the dynamic component the exact same mat-select works as expected. I also tried to create a dialog within my dynamic component and it also works fine (overlay container is attached to the body).

Every other functionality within the component is working as well (root services, ngrx store, ...).

There are no console errors.

Module imports contain MatSelectModule, MatInputModule & MatFormFieldModule.

Is this a bug or am I just missing something?

### Reproduction

1. add mat-select to popupComponent:
```


{{ status.id }}

```

2. Generate Component with createComponent(), using a generic EnvironmentInjector:

`const popupComponent: ComponentRef = createComponent(PopupComponent, {
environmentInjector: this._environmentInjector
});`

3. Add data to the component and execute change detection:

`component.instance.statuses = statuses;
component.changeDetectorRef.detectChanges();`

4. bind content to map popup (might be a possible source for the bug as well):

`mapMarker.bindPopup(popupComponent.location.nativeElement as Content);`

5. when opening the popup on the map and clicking on the select, the highlighting is correct, but nothing else happens:

![grafik](https://user-images.githubusercontent.com/125544629/225877898-4a2c8117-ce56-41ac-9fc0-37570d2e91da.png)

### Expected Behavior

mat-options should show up

### Actual Behavior

mat-options notshowing up, overlay container not attached

### Environment

- Angular: 15.0.2
- CDK/Material: 15.1.4
- Browser(s): Firefox 102.8

Guía de contribución

Abrir la guía de contribución

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.