2017-04-06 39 views
1

嗨我想檢查複選框,如果用戶選擇視圖複選框,它應該只選擇視圖複選框。如果用戶選擇編輯複選框,它應該同時選擇視圖和編輯複選框。這是一個plunker如何檢查兩個複選框同時在x可編輯使用角js

<td ng-click="profileform.$show()" align="center"> 
    <div> 
     <span e-ng-change="applyHighlight($data)" 
       editable-checkbox="Manage_Rolesui.View" 
       e-form="rowform" 
       ng-click="profileform.$show();"> 
      <input type="checkbox" 
        ng-model="Manage_Rolesui.View" 
        width="20"/> 
     </span> 
    </div> 
</td> 
<td ng-click="profileform.$show()" align="center"> 
    <span e-ng-change="applyHighlight($data)" 
      ng-checked="Manage_Rolesui.Edit" 
      editable-checkbox="Manage_Rolesui.Edit" 
      e-form="rowform" 
      ng-click="profileform.$show()"> 
     <input type="checkbox" 
       ng-model="Manage_Rolesui.Edit" 
       width="20"/> 
    </span> 
</td> 

回答

0

您可以使用ngChecked角指令自動檢查查看時,編輯被選中是這樣的:

<input type="checkbox" ng-model="Manage_Rolesui.View" width="20" /> 
<input type="checkbox" ng-model="Manage_Rolesui.Edit" ng-change="Manage_Rolesui.View = (Manage_Rolesui.Edit === true)" width="20" /> 

結帳的Official ngCheck documentation for more

或使用控制器

HTML

<div ng-controller="ExampleController"> 
    <label>View</label> 
    <input type="checkbox" ng-model="Manage_Rolesui.View" width="20" /> 
    <label>Edit</label> 
    <input type="checkbox" ng-model="Manage_Rolesui.Edit" ng-change="autoCheckView()" width="20" /> 
</div> 

控制器

angular.module('app', []); 

angular.module('app') 
.controller('ExampleController', ['$scope', function($scope) { 
    $scope.autoCheckView = function() { 
     $scope.Manage_Rolesui.View = ($scope.Manage_Rolesui.Edit === true) 
    } 
}]); 

運行例如:https://plnkr.co/edit/Y79wezief0bndhah4hdF?p=preview

+0

是啊,我想到這個問題的解決方案,但是這並不能完全滿足用戶的要求,。如果您取消選擇編輯,視圖也會被取消選中。 – lin

+0

好的,我已經更新了我的答案以符合您的需求。 Pure Angular;) –

+0

不要把這樣的邏輯放入視圖m8。 – lin

相關問題