Md Shifatul Islam Md Shifatul Islam - 6 months ago 15
Javascript Question

Check all check box and send all updated status as a Object [Angular Js]

I have used this

<div class="col-sm-12">
<form>
<input type="checkbox" onclick="for(c in document.getElementsByName('rfile')) document.getElementsByName('rfile').item(c).checked = this.checked" >Check All </button>

<table>
<thead>
<tr role="row">
<th>Student ID</th>
<th>Status</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="result in searchResults">
<td ><a href="#/Attendance/edit/{{result.id}}">{{result.studentId}}</a>
</td>
<td ><input type="checkbox" name="rfile" ng-model="result.status" /> {{result.status}}</td>
</tr>
</tbody>
</table>
<div>
<button ng-click="save()">Save</button>

</div>
</div>

</div>

</form>
</div>


It is perfectly checking all the checkbox but it is not updating the status.

what should i do.. When i click individual checkbox for updating it works perfectly.

TIA
I m beginner ..so please dont give down vote.

Answer

You must use ng-click or ng-change to manipulate your scope data and put all result status to true (or false).

Here a plunker to illustrate it : https://plnkr.co/edit/YW6opuPTgtXXg08OzbM6?p=preview

See your checkbox to check all

<input type="checkbox" ng-click="onCheckAll()" ng-model="checkAll">Check All