反之亦然ON / OFF在angularjs中切换

时间:2015-08-12 13:14:47

标签: angularjs html5

我正在使用程序中的两个ON / OFF开关。当一个开关打开时,另一个开关将自动关闭(反之亦然)。使用角度,给我你的建议。

<div class="onoffswitch">
    <input type="checkbox" name="onoffswitch" class="onoffswitch-checkbox" id="myonoffswitch">
    <label class="onoffswitch-label" for="myonoffswitch">
        <span class="onoffswitch-inner"></span>
        <span class="onoffswitch-switch"></span>
    </label>
</div>
<div class="onoffswitch">
    <input type="checkbox" name="onoffswitch" class="onoffswitch-checkbox" id="myonoffswitch">
    <label class="onoffswitch-label" for="myonoffswitch">
        <span class="onoffswitch-inner"></span>
        <span class="onoffswitch-switch"></span>
    </label>
</div>

1 个答案:

答案 0 :(得分:0)

是的,有角度可能。   - 将复选框状态保存到ng-model
  - 根据型号设置选定状态   - 您可以像这样使用ngTrueValue和ng-model的组合   - 利用ng-init设置元素的初始值

 <input type="checkbox" name="someName" value="0" ng-model="someValue" ng-true-value="0" ng-init="someValue=0">
 <input type="checkbox" name="someName" value="1" ng-model="someValue" ng-true-value="1">

这将在两个复选框之间交换检查状态。

如果我误解了你的意图,请给我留言。

相关问题