【发布时间】:2021-07-22 04:08:45
【问题描述】:
我在 Angular 11 中使用 mat select。任何人都可以帮我在 mat-select 中显示选定的选项。 我有一个名为 Idefault 的字段,条件是, 如果 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>
【问题讨论】:
-
我对material api不太熟悉,但是你不会只是在你的组件中预先定义
this.selectedBatchSource来分配默认值吗? -
感谢您的回复,但在这里我想在打开表单时显示选定的值。当用户从列表中选择选项时,我使用 selectedBatchSource 从列表中获取所选值。
标签: angular typescript angular-material