在angular2中的ngIf上重置ngModel值 [英] Reset ngModel values on ngIf in angular2
本文介绍了在angular2中的ngIf上重置ngModel值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个模型,它是一个数组元素.我想清除ngIf条件下每个元素的值.请在下面的HTML中找到:
I have a model which is an array element. I want to clear the values of each element on ngIf condition.Please find below HTML :
<div *ngIf="flag" >
<table id="table" class="table table-hover table-bordered table-mc-light-blue">
<thead>
<tr>
<th>col 1</th>
<th>col 2</th>
</tr>
</thead>
<tr *ngFor="let item of collection;">
<td>{{item.col1}}</td>
<td>
<input type="text" class="form-control" [(ngModel)]="item.col2" #input="ngModel" name="input-{{i}}">
</td>
</tr>
</table>
</div>
在标志上设置为false时,我想清除集合的所有值. 可以初始化集合,但是我不想这样做,因为我有几个这样的集合.
On flag set to false, I want to clear all values of the collection. There is an option of initializing collection, but I don't want to do that as I have several such collections.
任何帮助都是可取的!
推荐答案
<input type="radio" (change)="resetForm()"/>
resetForm(){
if(!this.flag){
this.collection = new Array()
}
}
这篇关于在angular2中的ngIf上重置ngModel值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文