Skip to content

Instantly share code, notes, and snippets.

@rlfrahm
Last active March 15, 2018 14:55
Show Gist options
  • Save rlfrahm/a7b94ef50bc382ffe767 to your computer and use it in GitHub Desktop.
Save rlfrahm/a7b94ef50bc382ffe767 to your computer and use it in GitHub Desktop.
Example of a check all checkbox in AngularJs

AngularJS : Check all checkboxes checkbox

#####Technologies

  • AngularJs
  • Twitter Bootstrap
angular.module('app',[])
.controller('CheckBoxCtrl',['$scope', function($scope) {
$scope.checkboxData = [
{label: 'Green',value: false},
{label: 'Red',value: false},
{label: 'Blue',value: true},
{label: 'Purple',value: true},
{label: 'Pink',value: false}
];
$scope.checkall = false;
$scope.toggleAll = function() {
$scope.checkall = !$scope.checkall;
for(var key in $scope.checkboxData) {
$scope.checkboxData[key].value = $scope.checkall;
}
};
}]);
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0/angular.min.js"></script>
<script src="app.js"></script>
<body ng-app="app"
<div class="checkbox-container" ng-controller="CheckBoxCtrl">
<div class="checkbox">
<label>
<input type="checkbox" ng-model="checkall" ng-click="toggleAll()"> Check all
</label>
</div>
<ul class="list-group">
<li class="list-group-item" ng-repeat="dataPoint in checkboxData">
<div class="checkbox">
<label>
<input type="checkbox" ng-model="dataPoint.value"> {{dataPoint.label}}
</label>
</div>
</li>
</ul>
</div>
</body>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment