首页 > 解决方案 > 在 Angular 的 mat-select 中显示默认选择的选项

问题描述

我在角度 11 中使用 mat select。任何人都可以帮我在 mat-select 中显示选定的选项。我有一个名为Idefault的字段,条件是 IF type.Idefault == true然后将值显示为 mat-select 中的选定选项

添加图片供您参考

在此处输入图像描述

             <div class="col-sm-6 has-select pr-3">
                  <mat-form-field appearance="fill" class="pt-1 no-border">
                    <mat-select formControlName="source"  [(ngModel)]="selectedBatchSource" (selectionChange)="changeClient($event.value)" >
                      <mat-option *ngFor="let type of data$ | async"  [value]="type.ctype">
                        {{type.ctype}}
                      </mat-option>
                    </mat-select>
                  </mat-form-field>
                </div>

标签: angulartypescriptangular-material

解决方案


 this.heroForm = new FormGroup({
    source: new FormControl('your default value here')
     
    ]),
使用反应形式我认为如果你这样做会有所帮助


推荐阅读