mat-select not pre selecting a value when mat-option has async content
See original GitHub issueBug, feature request, or proposal:
Bug
What is the expected behavior?
When the ngModel of a mat-select is populated on page load the mat-select should have that option selected.
What is the current behavior?
mat-select does not show the current selected option on page load if a mat-option has some async behaviour, in my case the translate pipe:
<mat-option *ngFor="let option of options" [value]="option.value">
{{ option.label | translate }}
</mat-option>
The current selected option is shown the moment the mat-select gets focus.
What are the steps to reproduce?
Please have a look at the following StackBlitz example: https://stackblitz.com/edit/angular-material2-issue-async-mat-option-label?file=app%2Fpet-select-async%2Fpet-select-async.component.ts
Which versions of Angular, Material, OS, TypeScript, browsers are affected?
material beta 12 angular 4.4.3
Issue Analytics
- State:
- Created 6 years ago
- Reactions:15
- Comments:13 (2 by maintainers)
Top Results From Across the Web
mat-select selected option not showing when ... - Stack Overflow
How do I go about making sure that selectedFood is pre-selected when options for the select component have been loaded?
Read more >Angular Material2 Issue Async Mat Option Label - StackBlitz
Issue template for @angular/material.
Read more >Select | Angular Material
Function to compare the option values with the selected values. The first argument is a value from an option. The second is a...
Read more >TIL: How to use async pipe and populate mat-select
I was trying to use async | pipe directly on the view to get all the country list and populate my mat... Tagged...
Read more >mat select all option stackblitz - You.com | The AI Search ...
Probably not. Open side panel. angular/componentsmat-select not pre selecting a value when mat-option has async content#7923. Created about 5 years ago.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
A terrible hack to use with dynamically loaded options that may or may not contain the currently selected item, but you want to show the select item info in the select trigger, is to always have the selected item as an option that is hidden.
<mat-option [value]="select.value" *ngIf="select.value" style="display: none">{{select.value}}</mat-option>
Or you could use
[compareWith]
and have it always return true as long as there is at least 1 option in your select box. Not sure which one is nastier.For now my workaround is like this Get labels
Bind in Template