I have three check boxes (parent 1, parent 2, parent 3) and in those three two by default checked (parent 1, parent 3)and one unchecked (parent 2) and when I checked the unchecked checkbox (parent 2) and click on clear button only those by default check boxes are unchecking(parent 1, parent 3) other one is remaining checked. here is the code :
<li *ngFor="let child of nestedjson; let i = index">
<input type="checkbox" [checked]="child.checked">
</li>
<div><button (click)="clear()" type="submit">clear</button></div>
in ts
nestedjson = [
{ name: 'parent1', value: ['child11', 'child12'], checked: true },
{ name: 'parent2', value: ['child2'], checked: false },
{ name: 'parent3', value: ['child3'], checked: true },
];
clear() {
this.nestedjson.forEach((child) => {
child.checked = false;
});
}
Aucun commentaire:
Enregistrer un commentaire