我在点击按钮时尝试重置选项值。我无法找到任何解决方案。我有一个组件,我正在使用此代码:
<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>
我的课程内部使用此代码:
options = ["Bar", "Pie", "Area"];
在循环内调用选项。我在按钮事件上使用此代码:
appendToContainer(){
// logic
this.options == null
}
我应该怎么做才能使其默认或为null
你的逻辑是正确的,但实现是错误的:
appendToContainer(){
// logic
this.options == null; // ==> WRONG expression
this.options = []; // ==> CORRECT
}