Angular 6 重置 select 选项 onclick
Angular 6 reset select options onclick
我正在尝试在单击按钮时重置选项值。我找不到任何解决方案。我有一个正在使用此代码的组件:
<select class='select-option' required [(ngModel)]='optionSelected' (ngModelChange)="toNumber()">
<option [ngValue]="undefined" disabled selected> Please select one option </option>
<option *ngFor='let option of options' [ngValue]="option">{{option}}</option>
</select>
在我的 class 中,我正在使用此代码:
options = ["Bar", "Pie", "Area"];
在循环中调用选项。我在按钮事件上使用此代码:
appendToContainer(){
// logic
this.options == null
}
我应该怎么做才能使其成为默认值或 null
你的逻辑是正确的,但是实现是错误的:
appendToContainer(){
// logic
this.options == null; // ==> WRONG expression
this.options = []; // ==> CORRECT
}
试试这个:
appendToContainer(){
// logic
this.options.value == this.options.options.first;//if the first options is 'Select'
}
我正在尝试在单击按钮时重置选项值。我找不到任何解决方案。我有一个正在使用此代码的组件:
<select class='select-option' required [(ngModel)]='optionSelected' (ngModelChange)="toNumber()">
<option [ngValue]="undefined" disabled selected> Please select one option </option>
<option *ngFor='let option of options' [ngValue]="option">{{option}}</option>
</select>
在我的 class 中,我正在使用此代码:
options = ["Bar", "Pie", "Area"];
在循环中调用选项。我在按钮事件上使用此代码:
appendToContainer(){
// logic
this.options == null
}
我应该怎么做才能使其成为默认值或 null
你的逻辑是正确的,但是实现是错误的:
appendToContainer(){
// logic
this.options == null; // ==> WRONG expression
this.options = []; // ==> CORRECT
}
试试这个:
appendToContainer(){
// logic
this.options.value == this.options.options.first;//if the first options is 'Select'
}