用枚举填充Angular 6中的select

时间:2019-05-24 22:41:18

标签: html angular typescript

我无法使用枚举在Angular 7应用程序中填充选择下拉列表。

我有这些枚举:

Export enum GenericApiEndpointMethods {
  GET,
  POST
}

这是我的选择

  <select [(value)]="endpoint.method" class="methodSelect">
    <option *ngFor="let method of GenericApiEndpointMethods" [value]="method">{{ GenericApiEndpointMethods[method] }}</option>
  </select>

但是什么都没有出现。不会填充该下拉列表,并且初始值未设置为任何值。

endpoint是组件中的对象,而endpoint.methodGenericApiEndpointMethods.GET

用枚举值填充选择下拉列表并将这些枚举的文本版本显示为下拉列表中的文本的正确方法是什么?以及如何将初始值设置为枚举之一?

0 个答案:

没有答案