3

Currently, I have this table with a checkbox at every row in AngularJS;

<table class="table table-hover data-table sort display">
<thead>
  <tr>
    <th>Name</th>
    <th>Location</th>   
    <th>Checkbox Alert</th>
  </tr>
</thead>
<tbody>
  <tr ng-repeat="item in filteredList | orderBy:columnToOrder:reverse">  
    <td>{{item.name}}</td>
    <td>{{item.location}}</td>  
    <td><input type="checkbox" ng-model="selected" ng-change="display(selected, item)"></td>  
  </tr>
</tbody>
</table>

I have a boolean variable {{item.checkbox_status}} which reflects whether the checkbox should be checked or unchecked. How should I place this variable into the table html code above to get the checkbox to reflect the checking status? Or do I need to work on the controller instead?

2
  • 2
    Still wondering why I got a -ve point? Stupid, trivial question? Not sure since there are so many better programmers on StackOverflow. What is easy for you is hard for me. Please be patient. Commented Jun 13, 2014 at 1:59
  • 1
    Completely agree with your point Commented Aug 30, 2016 at 11:45

4 Answers 4

3

ng-model is your answer.

i.e:

<input type="checkbox"  ng-model="item.checkbox_status" ng-click="alert_display()" ng-true-value="true" ng-false-value="false" />

Reference: https://docs.angularjs.org/api/ng/input/input%5Bcheckbox%5D

Hope I helped.

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

1 Comment

Should be more proper if wanted to use <input type="checkbox" ng-click="select(item)" ng-model="item.selected" ng-checked="item.selected">
1

just adding ng-model="item.checkbox_status" to the input should do the trick

1 Comment

Correct answer but I can only mark one of them as the correct answer. Sorry.
1

Normally, this should be enough :

<input type="checkbox" ng-model="item.checkbox_status" ng-change="display(selected, item)">

1 Comment

Correct answer but I can only mark one of them as the correct answer. Sorry.
1
use ng-checked for showing checked and unchecked status..
$scope.selectedThings=["a", "b", "c"];
$scope.availableThings=["a", "b", "c", "d", "e"];
<label class="col-md-6 checkbox" ng-repeat="data in availableThings">
<input type="checkbox" ng-checked="data && (availableThings.indexOf(data) !== -1)" />{{data}}
</label>

Comments

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.