Angular:change 结果跟随检查
Angular:change result follow checked
我想在 depositTasks 的 field checked 全部为 true 时更改结果,如果 depositTasks 的某些 field checked 有 false 给另一个结果。
app.html
<input type="checkbox" [(ngModel)]="task.checked" (click)="changChecked(task.checked)"
[ngModelOptions]="{standalone: true}">
app.ts
changChecked(checked) {
checked = !checked
if (this.depositTasks.length !== undefined) {
for (let i = 0; this.depositTasks.length > i; i++) {
if (this.depositTasks[i].checked === true ) {
console.log('do');
this.onSelectedStatus('Resolved')
} else {
this.onSelectedStatus('Assigned')
}
}
}
}
抱歉,不清楚您的目标是什么。这是一个如何确定是否所有复选框都被选中的解决方案:
HTML
<input type="checkbox" [(ngModel)]="task.checked" (change)="onChange()"
[ngModelOptions]="{standalone: true}">
TS
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');
}
}
}
我想在 depositTasks 的 field checked 全部为 true 时更改结果,如果 depositTasks 的某些 field checked 有 false 给另一个结果。
app.html
<input type="checkbox" [(ngModel)]="task.checked" (click)="changChecked(task.checked)"
[ngModelOptions]="{standalone: true}">
app.ts
changChecked(checked) {
checked = !checked
if (this.depositTasks.length !== undefined) {
for (let i = 0; this.depositTasks.length > i; i++) {
if (this.depositTasks[i].checked === true ) {
console.log('do');
this.onSelectedStatus('Resolved')
} else {
this.onSelectedStatus('Assigned')
}
}
}
}
抱歉,不清楚您的目标是什么。这是一个如何确定是否所有复选框都被选中的解决方案:
HTML
<input type="checkbox" [(ngModel)]="task.checked" (change)="onChange()"
[ngModelOptions]="{standalone: true}">
TS
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');
}
}
}