2016-04-15 141 views
0

我想做一个自举按钮,但我面临一些问题。切换按钮不是仅查看复选框显示,当我删除ngRepeat指令,然后它只适用于单个按钮,但我需要使用ngRepeat多个按钮。所以请帮助我。切换按钮与角ngrepeat

<div class="box-body" ng-controller="AutomationController"> 
    <div class="table-responsive"> 
    <table class="table table-hover "> 
     <thead> 
     <tr> 
      <th>Device Name</th> 
      <th>Status</th> 
      <th>Action</th> 
      <th>Edit Device Name</th> 
     </tr> 
     </thead> 
     <tbody> 
     <tr ng-repeat="device in devices"> 
      <td>[[device.dname]]</td> 
      <td> 
      <span ng-if="device.status===1">ON</span> 
      <span ng-if="device.status===0">OFF</span> 
      </td> 
      <td> 
      <input type="checkbox" checked data-toggle="toggle" ng-if="device.status===1"> 
      <input type="checkbox" checked data-toggle="toggle" ng-if="device.status===0"> 
      </td> 
      <td><a href="#"><i class="fa fa-pencil-square-o"></i></a></td> 
     </tr> 
     </tbody> 
    </table> 
    </div> 
</div> 

回答

0

检查jsfiddel

you should use radio button for toggle and bind that to status column. 
+0

感谢苏雷什但问题是不解决.. – user3220457

+0

检查jsfiddle我在上面的答案中创建 –

+0

检查小提琴的答案http://jsfiddle.net/sureshchahal/Lvc0u55v/2531/ –

0

首先,你周围有{{device.dname}},从而没有被正确呈现(不知道这是故意的)方括号。

根据设备状态,您有两个显示有条件显示的复选框。我会建议只使用一个复选框。

<input type="checkbox" data-toggle="toggle" ng-model="device.status" ng-true-value="1" ng-false-value="0"> 

正如你所看到的,你可以定义真值和假值(在你的情况为0或1),它显示并正确地更新变量的作用域。

如果您正在寻找它们设置为只读,一个ng-checked指令会做的伎俩:

<input type="checkbox" data-toggle="toggle" ng-checked="device.status" disabled="disabled"> 

尝试一下这里:

https://jsfiddle.net/r0m4n/ncfs6q5w/