Components: mat-select not setting value when using *ngFor to fill list

Created on 19 Sep 2018  路  4Comments  路  Source: angular/components

Bug, feature request, or proposal:

Maybe a bug.

What is the expected behavior?

I would expect the [(value)] binding on both of these mat-selects to work, but I can only get it to work on the first one.

image

this is the ts code

image

this is the result

image

So, only when not using the ngFor, does the [(value)] binding seem to work as expected.

What are the steps to reproduce?

https://stackblitz.com/edit/angular-1k7ykb?file=app%2Fselect-value-binding-example.html>

Which versions of Angular, Material, OS, TypeScript, browsers are affected?

Material 6.4.7
Angular 6.1.7

All 4 comments

Since you are trying to assign a object or variable as value of options, you'll need to add brackets around the "value" attribute, like [value]="o" will solve the problem.
Also consider using [(ngModel)] instead of [(value)] on the select.

See stackblitz: https://stackblitz.com/edit/angular-1k7ykb-cfmaq7

use [value]="o" or value="{{o}}" solve your problem.

@feeloor and @mungpara are correct. In your current example, the value for all the options is set to o. Closing as a non-issue.

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._

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jelbourn picture jelbourn  路  3Comments

constantinlucian picture constantinlucian  路  3Comments

michaelb-01 picture michaelb-01  路  3Comments

vitaly-t picture vitaly-t  路  3Comments

RoxKilly picture RoxKilly  路  3Comments