Bug
When the ngModel of a mat-select is populated on page load the mat-select should have that option selected.
mat-select is always showing the placeholder, I've tried using basic primitive values (numbers for the options and ngModel initialised with one of the numbers on page load) and the select is never reflecting the selected option.
I also added an example with a regular select and option to show that the code is working when not using material, hopefully that helps.
material beta 12
angular 4.3.2
Please update the plunkr examples with a working version
Try with the stackblitz from the issue template: https://goo.gl/wwnhMV
Thanks I hadn't tried the stackblitz, here is the link : mat-select issue
I also added an example with a regular select and option to show that the code is working when not using material, hopefully that helps.
I'll edit my first post to add it there too.
Ah ok, this is expected behavior. When you bind to value like this, you are actually binding as a string because {{ ... }} is the syntax for string interpolation.
value="{{ number }}"
Your values in numbersArray are of the type number, so by default, it will try to compare '2' === 2 which will return false.
Instead you should bind like this (you can read more about it here),
[value]="number"
That having been said, it is different than the native select, cc @crisbeto.
I'll admit we just figured it out and I was about to perform my walk of shame :)
Thanks for your help, we'll go with [value]="number"
this worked for me
`
<mat-select [ngModel]="sortLevel.SortOrder" (change)="setSortOrder($event)">
<mat-option [value]="0">{{'ASCENDING' | translate}}</mat-option>
<mat-option [value]="1">{{'DESCENDING' | translate}}</mat-option>
</mat-select>
`
Also the MatSelectChange.value is expressed as a number, now, too
<mat-option value=0> is an integer, but it is treated like a string in material2. This causes confusion when a standard select statement treats it as an integer.
This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
_This action has been performed automatically by a bot._
Most helpful comment
Ah ok, this is expected behavior. When you bind to
valuelike this, you are actually binding as astringbecause{{ ... }}is the syntax for string interpolation.Your values in
numbersArrayare of the typenumber, so by default, it will try to compare'2' === 2which will return false.Instead you should bind like this (you can read more about it here),
That having been said, it is different than the native select, cc @crisbeto.