【发布时间】:2019-12-03 16:05:52
【问题描述】:
我想在我的下拉列表中实现enum,但我在列表中同时获得了键和值。
我的枚举:
export enum VMRole {
"Kubemaster" = 0, "Kubeworker" = 1, "Other" = 2
}
我正在尝试将enum 分配给我的财产:
export class VirtualMachine {
role: VMRole;
...
}
我的组件:
export class AddVmComponent implements OnInit {
model: any = {};
@ViewChild('addVMForm', { static: false }) formValues;
constructor(private alertify: AlertifyService, private vm: VmService, private route:
ActivatedRoute, private http: HttpClient) {
this.model.role = Object.keys(VMRole).filter(p => typeof p !== 'number')
}
}
我的 HTML:
<select [ngModel]="model.role" class="form-control">
<option disabled>-Please choose role-</option>
<option *ngFor="let data of model.role | keyvalue">
{{data.value}}
</option>
</select>
截图:
【问题讨论】:
标签: html angular typescript