Skip to content

Instantly share code, notes, and snippets.

@kickboxer
Last active August 29, 2015 14:20
Show Gist options
  • Save kickboxer/0ce52f358feb4bb659d9 to your computer and use it in GitHub Desktop.
Save kickboxer/0ce52f358feb4bb659d9 to your computer and use it in GitHub Desktop.
Angular checkbox CheckAll
$scope.options = [
{value:'Option1', selected:true},
{value:'Option2', selected:false},
{value:'Option3', selected:false},
{value:'Option4', selected:false},
{value:'Option5', selected:false},
{value:'Option6', selected:false}
];
$scope.toggleAll = function() {
var toggleStatus = $scope.isAllSelected;
angular.forEach($scope.options, function(item){ item.selected = toggleStatus; });
};
$scope.optionToggled = function(){
$scope.isAllSelected = $scope.options.every(function(item){ return item.selected; });
<input type="checkbox" ng-click="toggleAll()" ng-model="isAllSelected">Select all
<div ng-repeat = "option in options">
<input type="checkbox" ng-model="option.selected" ng-change="optionToggled()">
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment