【问题标题】:Angular - Udefined value when trying get value of option value from a html select tagAngular - 尝试从 html 选择标签获取选项值时的未定义值
【发布时间】:2020-04-22 01:05:20
【问题描述】:

我想在我的角度组件的选择标签中更改选定选项时获取该值:

<select name="types" class="custom-select form-control rounded" (change)="changeType($event.target.value)">
  <option selected value="allTypes">Tous</option>
  <option *ngFor="let type of types; let i = index" [value]="types.id">
   {{types[i].name}
  </option>
</select>

  changeType(type) {
    this.chosenType = type
    console.log('changed type', type)
    this.getData()
  }

当日志选择类型我得到未定义!

【问题讨论】:

    标签: html typescript select events option


    【解决方案1】:

    使用ngValue解决问题

    【讨论】:

      猜你喜欢
      • 2017-05-04
      • 1970-01-01
      • 2022-07-16
      • 2016-07-28
      • 1970-01-01
      • 2021-12-20
      • 2019-08-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多