获取所选垫选项的text/html值在角度6中选择垫,角度材料2



在mat-select中获取所选选项的text/html最有效的方法是什么?

我真的很纠结该怎么做。

<mat-form-field class="w-100">
<mat-select class="w-100" placeholder="{{'Activities.haveEducation' | translate}}" formControlName="edu">
<mat-option value="1">{{'Shared.yes' | translate}}</mat-option>
<mat-option value="0">{{'Shared.no' | translate}}</mat-option>
</mat-select>                
</mat-form-field>

当没有表格时也是一样。我需要得到是/否,而不是所选选项的1或0

您可以使用所选选项的viewValue属性:

<mat-form-field class="w-100">
<mat-select #select class="w-100" placeholder="{{'Activities.haveEducation' | translate}}" formControlName="edu">
<mat-option value="1">{{'Shared.yes' | translate}}</mat-option>
<mat-option value="0">{{'Shared.no' | translate}}</mat-option>
</mat-select>                
</mat-form-field>
<div>
Selected: {{ select.selected?.viewValue }}
</div>

最新更新