Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug(mat-select): wrong initial values when using async object property #27220

Open
1 task done
madmurl0c opened this issue Jun 2, 2023 · 4 comments
Open
1 task done
Labels
area: material/select P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent

Comments

@madmurl0c
Copy link

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

14.2.12

Description

Hey everyone, if I try to access a property of an object loaded with the async pipe it appears to be empty until I click inside the mat-select element.

It's hard to explain so there's a stackblitz to show the issue.

Reproduction

https://stackblitz.com/edit/rjpwlz?file=src%2Fexample%2Fselect-no-ripple-example.html

Expected Behavior

The first mat-select in the example should initially display "2"

Actual Behavior

The first mat-select seems empty until you click on it

Environment

  • Angular: 16.0.4
  • CDK/Material: 16.0.3
  • Browser(s): Chrome 113.0.5672.127
  • Operating System (e.g. Windows, macOS, Ubuntu): Windows 11
@madmurl0c madmurl0c added the needs triage This issue needs to be triaged by the team label Jun 2, 2023
@zarend
Copy link
Contributor

zarend commented Jun 9, 2023

Hello @madmurl0c ,

Thank you for reaching out. I can reproduce on the linked stackblitz. This is interesting, and I'm wondering if it's a problem with the component, or with Angular in general.

Do you notice this behavior on other components, or just with mat-select?

Thanks,
Zach

@madmurl0c
Copy link
Author

Greetings @zarend,

Thanks for taking a look at this. I'm not 100% sure but I haven't noticed it with any other component in my apps so far. Manually triggering change detection doesn't seem to work either. I improved the stackblitz a bit but still no idea how to fix this issue

@mmalerba mmalerba added P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent area: material/select and removed needs triage This issue needs to be triaged by the team labels Jun 12, 2023
@Savvas-cl
Copy link

Is there any new regarding this. I have the exact same problem.

@fugazister
Copy link

Hi, i believe the culprit is located here https://github.com/angular/components/blob/main/src/material/core/option/option.ts#L271

If you have async pipe for selected option your first viewValue will be empty string. This means that after pipe update with populated value check https://github.com/angular/components/blob/main/src/material/core/option/option.ts#L271 will be falsey, hence no update

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: material/select P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent
5 participants