角材料垫选择 ngModel 布尔值不起作用

Mos*_*eri 1 angular-material ngmodel angular

我使用 mat-select 在 angular 7 项目和 angular material 中选择用户的性别

 <mat-form-field>
          <mat-select placeholder="Gender" required 
            formControlName="isMale" 
            [(ngModel)]="userProfile.isMale">
            <mat-option value="false">Women</mat-option>
            <mat-option value="true">Men</mat-option>
          </mat-select>
          <mat-hint align="end">Please Select...</mat-hint>
          <mat-error *ngIf="isControlHasError('isMale','required')"><strong>Please Select Gender</strong>
          </mat-error>
        </mat-form-field>
Run Code Online (Sandbox Code Playgroud)

userProfile 从服务器获取,isMale 属性是布尔类型,但获取数据后在 mat-select 上不显示所选值我也使用这种方式但不起作用

        <mat-option [value]="'false'">Women</mat-option>
        <mat-option [value]="'true'">Men</mat-option>
Run Code Online (Sandbox Code Playgroud)

但它不起作用

You*_*ani 7

这对我有用(我使用的是 Angular 8)

   <mat-form-field>
    <mat-select [(ngModel)]="userProfile.isMale">
      <mat-option [value]="true">Men</mat-option>
      <mat-option [value]="false">Women</mat-option>
    </mat-select>
  </mat-form-field>
Run Code Online (Sandbox Code Playgroud)

请注意,我使用 [value] = "true or false" 没有任何单个 cotes。显然, userProfile.isMale 应该是布尔值(真或假)。