Toggle checkbox in Angular JS relay table by clicking environment row
I have a table built with ng-repeat where each row has a checkbox set by a value in the JSON data that is repeated:
<tr ng-repeat="t in tabledata" ng-click="t.isChecked=t.!isChecked">
<td><input type="checkbox" ng-model="t.isChecked"></td>
<td>{{t.firstName}} {{t.lastName}}</td>
</tr>
I need to click on a line to toggle the value of a checkbox on that line. I tried the above but it doesn't work. Thoughts?
+3
source to share
1 answer
Try the following:
ng-click="t.isChecked = !t.isChecked"
The exclamation point must come before t.isChecked
.
Also make sure you stop propagating the click event on the checkbox yourself, otherwise clicking on the checkbox will prevent you from checking / unchecking the checkbox.
<input type="checkbox" ng-model="t.isChecked" ng-click="$event.stopPropagation()">
Demo: http://plnkr.co/edit/KJziWDmlN2gTbthOF4yJ?p=preview
+5
source to share