我有这个下拉列表的种族。我想要的是当我选择明确的种族时它不应该出现在选择框中,并且像盒子应该是空的。我怎样才能做到这一点?
<select
#ethnicity
[(ngModel)]="patient.Ethnicity"
[class.text-dimmed]="!patient.Ethnicity"
name="ethnicity"
id="ethnicity"
class="form-control input-underline input-lg ml-0">
<option [ngValue]="null" disabled> Select </option>
<option [ngValue]="null">Clear ethnicity</option>
<option value="Alaska-Native">Alaska Native</option>
<option value="American-Indian">American-Indian</option>
<option value="Asian">Asian</option>
<option value="African-Americans">Black or African American</option>
<option value="Hispanic">Hispanic or Latino</option>
<option value="Jewish-Ashkenazi">Jewish - Ashkenazi</option>
<option value="Jewish-Other">Jewish - Other</option>
<option value="Native-Hawaiians">Native Hawaiian or Other Pacific Islander </option>
<option value="Other">Other </option>
<option value="Unknown">Unknown </option>
<option value="White-Caucasian">White or Caucasian</option>
</select>
就像我选择它时,它看起来像这样
但我想要的是,
这是我的demo清晰的种族应该在下拉列表中显示,但当我选择它时,它不应该在选择框中显示,就像我共享屏幕截图
我该怎么做才能解决这个问题?谢谢。
你可以像这样处理选择标签的change event
。
onChange(value) {
if(value == 'Clear ethnicity'){
this.Ethnicity = '';
}
<select
#ethnicity
[(ngModel)]="Ethnicity"
[class.text-dimmed]="!Ethnicity"
name="ethnicity" (change)="onChange($event.target.value)"
id="ethnicity"
class="form-control input-underline input-lg ml-0">
但是:ぁzxswい
您所要做的就是删除“清除种族”这个值,就像我在下面所做的那样:
https://stackblitz.com/edit/angular-clear-option-select