【发布时间】:2020-10-18 17:45:21
【问题描述】:
当所选索引为 0 时,即“相同值”,我想传递 0 值而不是文本“相同值”。我们将如何操作数组来做到这一点?谢谢。
因为我需要在 UI 中显示“相同值”文本(请检查图像)作为选项,当用户选择它时,其值为 0
#HTML 组件
<div fxFlex fxLayout="row">
<mat-form-field appearance="outline" class="pr-4" fxFlex>
<mat-label>Select Month</mat-label>
<mat-select formControlName="month_" required>
<mat-option *ngFor="let month of months;" [value]="month">
{{month}}
</mat-option>
</mat-select>
</mat-form-field>
</div>
#TS 组件
export class MonthSelectorComponent implements OnDestroy, OnInit {
public months = ["Same Value", 1, 2, 3, 6, 12];
.................
【问题讨论】:
标签: angular typescript