我的表单中有两个选择列表(select1 和 select2),select2 取决于 select2 选择,当 select2 中的 select1 选择更改选项必须更改时,这项工作正常,但我的问题是更改后不会返回默认选项,它给了我最后一个 select2 选择的最后一个索引, 我想更改 select2 选项更改和所选选项的索引返回 0 或默认选项 我正在使用 ng-model 来处理 angular2 中的选择
这是我的 html 代码:
<td *ngIf="classificationCheck"><select name="classification_type" [(ngModel)]="message.classification_type"
class="form-control" [disabled]="isReply||isForward">
<option value="" disabled default>تصنيف موضوعي</option>
<option *ngFor= "let subType of classificationTypes">{{subType}}</option>
</select></td>
和 select1 的 onChange 函数更新 select2 选项:
classificationChange( event ){
if("غير محدد"==event){
this.classificationCheck=false;
this.message.classification_type=null;
}
else{
for(let classtype of this.classifications){
if(classtype.gen==event){
if(classtype.name)
{
this.classificationTypes=[];
this.classificationCheck=true;
for(let subType of classtype.name){
this.classificationTypes.push(subType);
}
}
}
}
}
}
最佳答案
在您的选择上放置一个*ngIf
。将其设置为真。当您想要重置时,将其设置为 false,然后很快恢复为 true。
在合适的方法可用之前,这是 RC4 中的官方方法。
我不知道 ng2 的最终版本现在是否有新方法可用。
关于html - 如何在angular2中重置选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40281110/