如何在ng-repeat中绑定表中的单个复选框值?

时间:2015-10-21 10:58:12

标签: angularjs checkbox

我在数据库中有一个包含5行的服务表,我通过ng-repeat显示它。我只想选择一个复选框值

<tbody>
     <tr data-ng-repeat="serviceTable in dataTable ">  
        <td> {{ serviceTable.serviceId }} </td>
        <td> {{ serviceTable.serviceName }} </td>
        <td> {{ serviceTable. amount }} </td>
        <td><input type="checkbox" ng-model="?????"></td>
     </tr>
</tbody>

如何只绑定ng-model中的一个值???

1 个答案:

答案 0 :(得分:0)

就像那样:

<input type="checkbox" ng-model="item.yourBoolValue">

您还可以提供两个附加指令,以便为已选中和未选中的样式使用特定值:

   <input type="checkbox" ng-model="item.checkValue" ng-true-value="1" ng-false-value="0">

修改

我一开始并不理解这个问题。 你不想使用单选按钮吗?

<input type="radio" name="radioGroupName" ng-model="item.boolValue" />

它们使您能够只从组中选择1项(这就是为什么必须设置名称属性),而无需任何其他逻辑。