【发布时间】:2017-09-25 06:26:45
【问题描述】:
我有一个模型,它是一个数组元素。我想清除 ngIf 条件下每个元素的值。请在 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>
在 flag 设置为 false 时,我想清除 collection 的所有值。 有一个初始化 collection 的选项,但我不想这样做,因为我有几个这样的集合。
任何帮助将不胜感激!
【问题讨论】:
-
flag的值什么时候会发生变化?在什么情况下会发生变化? -
实际上,没有事件,我将标志变量绑定到单选按钮作为 ngmodel。在更改单选按钮时,我正在显示内容
-
谢谢。 . . .. .
标签: angular angular2-template angular2-forms angular2-services