简体   繁体   English

AngularJS主复选框切换器

[英]AngularJS master checkbox toggler

Is it possible with AngularJs to do: master checkbox which turn on/off it child checkboxes - each one of them showing a different content. 使用AngularJs可以做到:主复选框打开/关闭子复选框-每个复选框都显示不同的内容。 Plunker enter code here 柱塞 enter code here

Yes, you can create a master checkbox toggle. 是的,您可以创建一个主复选框切换。 Here's a working plunkr . 这是一个正在工作的朋克

View 视图

<input type="checkbox" ng-model="selectAll" ng-click="checkAll()" />
<input type="checkbox" ng-model="checkbox[0].selected" />
<input type="checkbox" ng-model="checkbox[1].selected" />
<input type="checkbox" ng-model="checkbox[2].selected" />

Controller 调节器

// Check/uncheck all boxes
$scope.checkAll = function () {
  angular.forEach($scope.checkbox, function (obj) {
    obj.selected = $scope.selectAll;
  });
};

add the model to the 'ng-checked' expression 将模型添加到“ ng-checked”表达式中

  <input id="checkSlave" type="checkbox" ng-checked="master || slave1" ng-model="slave1" aria-label="Slave input">
  <input id="checkSlave" type="checkbox" ng-checked="master || slave2" ng-model="slave2" aria-label="Slave input">
  <input id="checkSlave" type="checkbox" ng-checked="master || slave3" ng-model="slave3" aria-label="Slave input">

add 'master' into ng-show expression 在ng-show表达式中添加“ master”

<div ng-show="slave1 || master">Slave one showed!</div>
<div ng-show="slave2 || master">Slave two showed!</div>
<div ng-show="slave3 || master">Slave three showed!</div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM