我无法在我的页面上为 select 设置默认值。我从数据库中收集值,目前我只有一个值,这就是我想将其设置为默认值的原因。
这是我的代码:
<mat-form-field appearance="fill">
<mat-select (selectionChange)="contractSelect($event.value)">
<mat-option *ngFor="let contractType of contracTypes" [value]="contractType">
{{contractType.description}}
</mat-option>
</mat-select>
</mat-form-field>
答案 0 :(得分:0)
假设 contractType
存在,您可以在 mat-select
处添加双向绑定,如下面的代码:
<mat-form-field appearance="fill">
<mat-select (selectionChange)="contractSelect($event.value)" [(ngModel)]="{{CONTRACT_TYPE_VARIABLE_ON_TS}}">
<mat-option *ngFor="let contractType of contracTypes" [value]="contractType">
{{contractType.description}}
</mat-option>
</mat-select>
</mat-form-field>