Reputation: 459
I have an array, that contains objects. Each object has a boolean varaible (array[i].check). I want to make a table using AngluarJS that by clicking on a checkbox it directly change a boolean value of a specific object within my array.I use:
<table>
<tr data-ng-repeat="a in array">
<td style="width:200px;"> {{a.name}}</td>
<td><input type="checkbox" ng-model="a.check" ng-checked="a.check"></td>
</tr>
</table>
But the value of every boolean remains false always. What I am doing wrong?
Upvotes: 0
Views: 90
Reputation: 58757
Can you try this method of using ng-model
alone, I have created a fiddle with the working method, apply this code, then share back with the issue and I will resolve it for you!
var app = angular.module('myApp', []);
app.controller('MyController', function MyController($scope) {
$scope.array = [{id:1, name: "test1", changeThisValue: false},{id:2, name: "test2", changeThisValue: true},{id:3, name: "test3", changeThisValue: true},{id:4, name: "test4", changeThisValue: true},{id:5, name: "test5", changeThisValue: true}];
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-controller='MyController' ng-app="myApp">
<table>
<tr data-ng-repeat="a in array">
<td style="width:200px;"> {{a.name}}</td>
<td>
<input type="checkbox" ng-model="a.changeThisValue">
</td>
</tr>
</table>
<pre style="width:100px;white-space: pre-wrap;">{{array}}</pre>
</div>
Upvotes: 1