0

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?

8
  • 1
    Is the value of a.check a Boolean or a String? In other words if you look at the actual value is it false or "false"? Commented Oct 17, 2017 at 19:31
  • 1
    Additionally, you shouldn't mix ngModel and ngChecked. See the docs: ngChecked. Commented Oct 17, 2017 at 19:32
  • a.check is boolean, as received from REST server as boolean Commented Oct 17, 2017 at 19:34
  • 1
    Then try only using ngModel instead of both. Commented Oct 17, 2017 at 19:35
  • nope still no effect...I have tried just ng-checked and ng-model separately Commented Oct 17, 2017 at 19:37

1 Answer 1

1

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>

Sign up to request clarification or add additional context in comments.

2 Comments

using just ngModel worked! the first time i have tried I made a mistake that didn't noticed.....
@AlexP Glad you fixed it!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.