2016-02-29 53 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> 
相关问题