首页 > 解决方案 > 选择选项角度2

问题描述

你好,与select选项相关的问题,这个人的属性是男M,在选择中必须有选择性别并用F改变它的可能性。属性是男entity.person.sex = 'M' 的,女的是entity.person.sex = 'F'

html

<span >
    <span >
        <span >Sesso</span>
        <span ></span>
        <select name='gender'>
            <option [value]='' selected>{{entity.person.sex}}</option>
            <option [ngValue]="">{{}}</option>
        </select>
    </span>
</span>

标签: angulartypescript

解决方案


您需要为更改事件调用一个函数:

 <select name='gender' (change)="selectChangeHandler($event)">
      <option ....
 </select>

零件:

selectChangeHandler (event: any) {
    //update the ui
    this.entity.person.sex = event.target.value;
  }

推荐阅读