Angular 角度:检查更改结果
我想更改depositTasks的字段选中时的结果,如果depositTasks的某些字段选中时的结果为假,则另一个结果为假 app.htmlAngular 角度:检查更改结果,angular,angular8,Angular,Angular8,我想更改depositTasks的字段选中时的结果,如果depositTasks的某些字段选中时的结果为假,则另一个结果为假 app.html <input type="checkbox" [(ngModel)]="task.checked" (click)="changChecked(task.checked)" [ngModelOptions]="{standalone: true}"> 对不起,
<input type="checkbox" [(ngModel)]="task.checked" (click)="changChecked(task.checked)"
[ngModelOptions]="{standalone: true}">
对不起,你的目标是什么还不清楚。以下是如何确定是否选中所有复选框的解决方案: HTML
<input type="checkbox" [(ngModel)]="task.checked" (change)="onChange()"
[ngModelOptions]="{standalone: true}">
我的目标是当所有复选框都选中时:true以执行此操作。onSelectedStatus('Resolved')但如果选中所有复选框:false以执行此操作。onSelectedStatus('Assigned')好的,我根据您的需要调整了代码。如果合适,请将此答案标记为解决方案。Thx提前。
<input type="checkbox" [(ngModel)]="task.checked" (change)="onChange()"
[ngModelOptions]="{standalone: true}">
onChange(): void {
if (this.depositTasks) {
// when there is no element with checked state of false, the result is -1
// and when the result is -1 our comparison returns true
const allChecked = (this.depositTasks.findIndex(task => task.checked === false) === -1);
if (allChecked) {
this.onSelectedStatus('Resolved');
} else {
this.onSelectedStatus('Assigned');
}
}
}