I made a check box that I can select from the list using the method below.
component.html
<td class="td"> ← The area of the check box.
<ion-checkbox
[(ngModel)]="data.isChecked"
(ionChange)="checkBox(data.isChecked)" ← An event occurs when you actually click it.
></ion-checkbox>
</td>
The relevant codes are as follows.
component.ts
checkBox(clicked) {
this.isUpdateBtnEnabled = clicked;
for (let i = 0; i < this.List.length; i++) { ← [this.list] is a variable that contains the data in that list.
if (this.List[i].isChecked) {
this.isUpdateBtnEnabled = this.List[i].isChecked;
break;
}
}
}
It works normally, but in addition to this, when I first loaded the page, I want all the check boxes selected. Here’s what I’ve tried.
1>
component.html → checked=“true”
<td class="td"> ← The area of the check box.
<ion-checkbox
checked="true" ← It will not work unless you erase the two lines below. This is not usable.
[(ngModel)]="data.isChecked"
(ionChange)="checkBox(data.isChecked)"
></ion-checkbox>
</td>
2>
component.ts
ngOnInit() {
document.getElementsByClassName(“td”)[0].click();
} ← error. This is not usable too…
3>
ngOnInit() {
let form = document.getElementById(‘td’);
if (form) {
(form as HTMLFormElement).click();
} ← There is no error, but it is not selected. This is not usable too…
}
If it’s just for selection, you can use it, but how do you initialize it as all selected, while maintaining the existing functionality as well?
I need help, please.