2016-02-29 85 views

回答

0
<input type="checkbox" ng-true-value="none" ng-click="clearAll()" ng-model="clearMe"> 

Javascript代碼

$scope.clearAll=function(){ 
    $scope.selectMe1=false; 
    $scope.selectMe2=false; 

} 
+0

這是工作,謝謝,我想問一件事,我們可以做些什麼來禁用未經檢查的複選框。 –

+0

橙色 粉色 並添加$ scope.disableMe1 = false和$ scope.disableMe2 = false; –

0

ng-click一個toggle功能應該可以幫助您。嘗試這個。

<input type="checkbox" ng-true-value="0" ng-model="clearMe" ng-click="toggle()">None 

在你的控制器,你可以添加

$scope.toggle = function() 
{ 
    $scope.selectMe1 = 'false'; 
    $scope.selectMe2 = 'false'; 
} 
0

這是一個樣本,可以幫助你:

的Html

<div> 
    <ul ng-controller="checkboxController"> 
     <li>Check All 
      <input type="checkbox" ng-model="selectedAll" ng-click="checkAll()" /> 
     </li> 
     <li ng-repeat="item in Items"> 
      <label>{{item.Name}} 
       <input type="checkbox" ng-model="item.Selected" /> 
      </label> 
     </li> 
    </ul> 
</div> 

的Javascript

angular.module("CheckAllModule", []) 
    .controller("checkboxController", function checkboxController($scope) { 


    $scope.Items = [{ 
     Name: "Item one" 
    }, { 
     Name: "Item two" 
    }, { 
     Name: "Item three" 
    }]; 
    $scope.checkAll = function() { 
     if ($scope.selectedAll) { 
      $scope.selectedAll = true; 
     } else { 
      $scope.selectedAll = false; 
     } 
     angular.forEach($scope.Items, function (item) { 
      item.Selected = $scope.selectedAll; 
     }); 

    }; 


}); 

this a working demo

0

您最後複選框ng-change=disableall()添加到這一點你最後的複選框,

控制器上:

$scope.selectMe1 = false;//init 
$scope.selectMe2 = false;//init 
$scope.clearMe = false;//init 

$scope.disableall() = function(){ 
    //let's say that you clear when the checkbox is true 
    if($scope.clearMe){ 
      $scope.selectMe1 = false; 
      $scope.selectMe2 = false;   
    } 
} 

希望有所幫助,祝你好運。

0

簡單的解決方案:

<input type="checkbox" ng-model="selectMe1">Orange 
<input type="checkbox" ng-model="selectMe2">Pink 

<input type="checkbox" ng-model="clearMe" ng-click="selectMe1=selectMe2=0;">None 
+0

這是工作,但我有40個複選框。 –

+0

所以你必須使用代碼 – MBN

+0

當我試圖在ng-click上使用代碼,並將該值設置爲flase,但是我的ng值和ng-model像性質.question28.options.option1_CHECKBOX,angular不接受這個表示法 –

0
try this, 
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"> </script> 
<div ng-app="app" ng-controller="ctrl"> 
<form id="selectionForm"> 
    <input type="checkbox" ng-click="toggleAll()" >Select all 
    <br> 
    <div ng-repeat = "option in options"> 
     <input type="checkbox" ng-model="option.selected" ng-change="optionToggled()">{{option.value}} 
    </div> 
</form> 
    {{options}} 
</div> 

<script> 
angular.module("app", []).controller("ctrl", function($scope){ 

    $scope.options = [ 
    {value:'Option1', selected:true}, 
    {value:'Option2', selected:false} 
    ]; 

    $scope.toggleAll = function() { 
    var toggleStatus = false; 
    angular.forEach($scope.options, function(itm){ itm.selected = toggleStatus; }); 

    } 

}); 
</script> 
相關問題