在选择默认选项,与活性形式

问题描述 投票:0回答:1

我有我的选择一个选项,以过滤我所有的结果和其他选项列表,我可以从我的列表中设置默认选项,但不能设置第一垫选项为默认值。我怎样才能做到这一点?

  <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个回答
1
投票

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

<mat-option [value]="0">(All)</mat-option>
© www.soinside.com 2019 - 2024. All rights reserved.