Check and uncheck all checkbox using Angularjs
By Hardik Savani | November 17, 2018 | | 5461 Viewer | Category : AngularJSIn this post, i would like to show you how to check uncheck checkboxes in angularjs. we mostly require to do check unselect all checkbox when we are doing multiple select items, multiple delete item etc task on your web app.
Here, i will show you two way to make all checkbox checked and unchecked on button click event in angular js. i also give you demo. so you can check also there. we will use ng-model and ng-checked for doing simple check uncheck toggle event. in another example we will use ng-checked and ng-click. So let's see both example.
Example 1:
<!doctype html>
<html>
<head>
<title>Check and uncheck all checkbox using Angularjs - ItSolutionStuff.com</title>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>
</head>
<body ng-app='myapp'>
<div ng-controller="myCtrl">
<input type='checkbox' value='' ng-model='checkAll' >Check/Uncheck All<br/>
<input type='checkbox' ng-checked="checkAll" >AngularJS<br/>
<input type='checkbox' ng-checked="checkAll">VueJS<br/>
<input type='checkbox' ng-checked="checkAll">JQuery<br/>
<input type='checkbox' ng-checked="checkAll" >PHP<br/>
</div>
</body>
<script type="text/javascript">
var app = angular.module('myapp', []);
app.controller('myCtrl', ['$scope', '$http', function ($scope, $http) {
}]);
</script>
</html>
Example 2:
<!doctype html>
<html>
<head>
<title>Check and uncheck all checkbox using Angularjs - ItSolutionStuff.com</title>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>
</head>
<body ng-app='myapp'>
<div ng-controller="myCtrl">
<input type='button' id='but_checkall' value='Check all' ng-click='checkAll()'>
<input type='button' id='but_uncheckall' value='Uncheck all' ng-click='uncheckAll()'>
<br/>
<input type='checkbox' ng-checked="checkall" >AngularJS<br/>
<input type='checkbox' ng-checked="checkall">VueJS<br/>
<input type='checkbox' ng-checked="checkall">JQuery<br/>
<input type='checkbox' ng-checked="checkall" >Laravel<br/>
</div>
</body>
<script type="text/javascript">
var app = angular.module('myapp', []);
app.controller('myCtrl', ['$scope', '$http', function ($scope, $http) {
$scope.checkAll = function(){
$scope.checkall = true;
}
$scope.uncheckAll = function(){
$scope.checkall = false;
}
}]);
</script>
</html>
I hope it can help you...
Featured Post
- AngularJS Drag and Drop Table Rows Example with Demo
- PHP AngularJS populate dynamic dropdown example
- AngularJS - Add Remove Input Fields Dynamically with PHP MySQLi
- AngularJS Ajax Autocomplete Using Typeahead in PHP Example
- How to copy to clipboard without flash in AngularJS ?
- AngularJS - How to render HTML value in ng-repeat ?
- AngularJS - scroll to a specific element using anchorscroll
- AngularJS - convert comma separated string to array example