选中AngularJS中的所有复选框

帕特·沃拉(Parth Vora)

我是AngularJS的新手。请查看以下内容:

在此处输入图片说明

现在,当用户单击“所有”链接时,应选中所有11个复选框,而当用户单击“无”链接时,则应取消选中所有11个复选框

另外,当用户选中“所有其他”复选框时,应选中所有底部的9个复选框,而当用户取消选中“所有其他”复选框时,则应取消选中所有底部的9个复选框

我可以一次完成一项任务,但不能同时完成。因此,有人可以帮助我同时完成两项任务吗?

任何帮助,将不胜感激。

海边古普塔

您可以使用

的HTML

<body ng-controller="MainCtrl">
    <button ng-click="selectAll()">Select All</button>
    <button ng-click="clearAll()">Clear All</button>
    <input type="checkbox" ng-model="select" ng-click="checkAll()" />
    <br />

    <p>Checkboxes</p>
    <input type="checkbox" ng-repeat="c in checkbox" ng-model="checkbox[$index].selected">
</body>

角度的

var app = angular.module('plunker', []);

app.controller('MainCtrl', function($scope) {
  $scope.checkbox = [
    {
      selected: false
    },
    {
      selected: false
    },
    {
      selected: false
    }
  ];
  // Check/uncheck all boxes
  $scope.selectAll = function () {
    $scope.select = true;
    angular.forEach($scope.checkbox, function (obj) {
        obj.selected = true;
    });
  };

  $scope.clearAll = function () {
    $scope.select = false;
    angular.forEach($scope.checkbox, function (obj) {
        obj.selected = false;
    });
  };

  $scope.checkAll = function () {
    angular.forEach($scope.checkbox, function (obj) {
        obj.selected = $scope.select;
    });
  };
});

弄小提琴

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章