dshukertjr
dshukertjr

Reputation: 18740

Angular Material mat-select set default selected value

I am using Angular 7 and Angular Material. I want my to have a default value, but it is not working as expected.

 <mat-select required [(value)]="userProfile.gender">
    <mat-option value="Male">Male</mat-option>
    <mat-option value="Female">Female</mat-option>
  </mat-select>

userProfile does have a property and the value is Male in my test case, but nothing is being selected in the html. What am I doing wrong?

Upvotes: 1

Views: 16846

Answers (1)

dshukertjr
dshukertjr

Reputation: 18740

I don't know why, but changing [(value)] to [(ngModel)] solved it

  <mat-select required [(ngModel)]="userProfile.gender">
    <mat-option value="Male">Male</mat-option>
    <mat-option value="Female">Female</mat-option>
  </mat-select>

Upvotes: 2

Related Questions