Santanu Santanu - 3 months ago 8
AngularJS Question

How to check checkbox in ng-repeat in angularjs

I have a html table which is binding using Angularjs.Now i want to select checkbox during ng-repeat with a condition.

<tbody>
<tr class="gradeX" ng-repeat="itm in usersList">

<td>
<input type="checkbox"/></td>
<td> {{itm.FirstName}}</td>

<td>{{itm.Email}}</td>

</tr>
</tbody>


I have another field itm.checkstatus.i want to check the checkbox during ng-repeat when itm.checkstatus=1 then checkbox will check else checkbox will not check.how to do this?

Answer

You can use ng-checked for this:

https://docs.angularjs.org/api/ng/directive/ngChecked

 <tbody>
      <tr class="gradeX" ng-repeat="itm in usersList">
         <td><input type="checkbox" ng-checked="itm.checkstatus == 1" /></td>
         <td>{{itm.FirstName}}</td>
         <td>{{itm.Email}}</td>
      </tr>
  </tbody>
Comments