I have a table in my HTML and one of the cells in every row there is a input check box.
Now I am trying to check if the checkbox is selected or not and below is what I have tried.
HTML:
<table class="table table-hover" id="just_a_table">
<thead>
<tr>
<th scope="col">Select</th>
<th scope="col">IP Addr</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let data of instances">
<td><input type="checkbox" (click)='onSelect()'></td>
<td>{{data["IP"]}}</td>
</tr>
</tbody>
</table>
TS:
onSelect() {
// We get the table data from the html and find if the checkbox is active.
// The rows of the tables can be accessed by "rows" object and cells can be accessed using "cells" object.
this.table_data = document.getElementById("just_a_table")
for (var i=1, row; row = this.table_data.rows[i]){
for (var j=0, cell; cell = row.cells[j]){
if (<HTMLInputElement>cell[1].checked){
console.log("It is checked")
}
}
}
}
I am doing it this, way because I do not want to get the input element with it's ID and see if it checked.
Any help/directions here would be really appreciated.
ngModelbindings?data, or instead create a new array (calledchecksfor example), change your*ngForto include the index (*ngFor="let data of instances, i = index), and then bind to your array with[(ngModel)]="checks[i]"