【发布时间】:2017-12-09 16:21:28
【问题描述】:
我使用*ngFor 来填充我的表格。
<tr *ngFor= "stu in students">
<td>{{stu.name}}</td>
<td><input type="checkbox" ngModel="isChecked"
(ngModelChange)="addID(stu.id)</td>
</tr>
然后我在桌子外面有一个按钮。
<button (click)="selectAllID()">select all</button>
然后我的组件为:
studentID=[];
isChecked=false;
addID(id:number){
this.student.push (id);
//I do other thing with id
}
selectAllID (){
If (this.isChecked)
this isChecked = false;
else this isChecked = true
}
问题是:
如果我选中单个复选框,则会执行 addID() 函数。但是,如果我单击全选按钮,则会选中复选框。但是addID()函数没有被调用。
当我使用全选按钮时,如何触发ngModelChange 函数,以便我选择所有id's
【问题讨论】:
-
在 ngModel 上使用括号作为 [ngModel]="isChecked"
标签: html angular forms checkbox