Components: mat-select do not set the pre-selected value with the ngModel when the option is an object

Created on 3 Nov 2017  路  3Comments  路  Source: angular/components

Bug, feature request, or proposal:

            <mat-form-field>
                  <mat-select name="role" [(ngModel)]="user.role">
                    <mat-option *ngFor="let role of roles" [value]="role">
                      {{ role.name }}
                    </mat-option>
                  </mat-select>
                </mat-form-field>

What is the expected behavior?

the mat has to set the user's role as the default selected value

What is the current behavior?

Initially, the mat-select is empty unless I select one of the options (the selection changes are reflected to the user.role so this is a correct behaviour)

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

angular 4.4.6
material 2.0.0-beta.12

Is there anything else we should know?

I know it seems that this issue had been answered in #7771. But that case is with simple value types (number or string) . My issue appears when the value is an object

Most helpful comment

See the paragraph here about compareWith.

EDIT: Should be on the material.angular.io docs after the next release.

All 3 comments

See the paragraph here about compareWith.

EDIT: Should be on the material.angular.io docs after the next release.

Also take a look at @rafaelss95's example here: https://github.com/angular/material2/issues/6970#issuecomment-328355857

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