【问题标题】:Default option in select, with reactive forms选择中的默认选项,具有反应形式
【发布时间】:2019-06-28 03:05:53
【问题描述】:

我的选择中有一个选项来过滤我的所有结果和其他选项列表,我可以从我的列表中设置默认选项,但不能将第一个 mat-option 设置为默认值。我该怎么做?

  <mat-form-field class="col-md-12 p-0 pb-2">
    <mat-select formControlName="carControl">
      <mat-option value="0">(All)</mat-option>
      <mat-option *ngFor="let item of data.filteredListOfCars" [value]="item" ngDefaultControl>
        {{this.codeListService.getNameOfManufacturerById(item.manufacturerId)}} {{item.model}} {{item.ecv}}
      </mat-option>
    </mat-select>
  </mat-form-field>

我正在设置这样的默认值

selectValueInControl(){
    this.filterFormGroup.get('statusControl').setValue(0);
} 

【问题讨论】:

    标签: html angular typescript angular-reactive-forms


    【解决方案1】:

    使用[value]="0" 代替value="0"

    <mat-option [value]="0">(All)</mat-option>
    

    【讨论】:

      猜你喜欢
      • 2018-05-02
      • 1970-01-01
      • 2020-05-19
      • 2017-11-26
      • 2018-12-19
      • 2021-05-02
      • 2020-06-07
      • 1970-01-01
      • 2017-09-02
      相关资源
      最近更新 更多