Я пытаюсь установить флажок «выбрать все», который будет устанавливать все флажки, что нормально, но когда я нажимаю на другие флажки, кроме «выбрать все», он снова выбирает все флажки
HTML-файл
<div class="form-check mt-3">
<label class="form-check-label text-dark font-weight-bold">
<input class="form-check-input" type="checkbox" value="" [(ngModel)]="selectedAll" [ngModelOptions]="{standalone:
true}" (change)="selectAll()">
Select All
<span class="form-check-sign">
<span class="check"> </span>
</span>
</label>
</div>
<div *ngFor="let a of name">
<div class="d-flex justify-content-between">
<!--------------------div to justify content --------------------->
<div class="">
<div class="form-check mt-3">
<label class="form-check-label text-dark">
<input class="form-check-input" type="checkbox" value="" [(ngModel)]="a.selected" [ngModelOptions]="{standalone:
true}" (change)="checkIfAllSelected()">
Household Information
<span class="form-check-sign">
<span class="check"> </span>
</span>
</label>
</div>
<div class="form-check mt-3">
<label class="form-check-label text-dark">
<input class="form-check-input" type="checkbox" value="" [(ngModel)]="a.selected" [ngModelOptions]="{standalone:
true}" (change)="checkIfAllSelected()">
House Images
<span class="form-check-sign">
<span class="check"> </span>
</span>
</label>
</div>
<div class="form-check mt-3">
<label class="form-check-label text-dark">
<input class="form-check-input" type="checkbox" value="" [(ngModel)]="a.selected" [ngModelOptions]="{standalone:
true}" (change)="checkIfAllSelected()">
Map Access
<span class="form-check-sign">
<span class="check"> </span>
</span>
</label>
</div>
</div>
Ts файл
selectAll() {
for (let i = 0; i < this.name.length; i++) {
{
this.name[i].selected = this.selectedAll;
}
}
}
checkIfAllSelected() {
console.log(this.name);
this.selectedAll = this.name.every(function(item: any) {
console.log(item);
return item.selected == true;
})
}