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

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

Closed
ikramcheb opened this issue Nov 3, 2017 · 3 comments

Comments

@ikramcheb
Copy link

@ikramcheb ikramcheb commented Nov 3, 2017

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

@willshowell
Copy link
Contributor

@willshowell willshowell commented Nov 3, 2017

See the paragraph here about compareWith.

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

@julianobrasil
Copy link
Contributor

@julianobrasil julianobrasil commented Nov 3, 2017

Also take a look at @rafaelss95's example here: #6970 (comment)

@jelbourn jelbourn closed this Nov 3, 2017
@angular-automatic-lock-bot
Copy link

@angular-automatic-lock-bot angular-automatic-lock-bot bot commented Sep 7, 2019

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.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 7, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants
You can’t perform that action at this time.