The ng-checked Directive in AngularJS is used to read the checked or unchecked state of the checkbox or radiobutton to true or false. If the expression inside the ng-checked attribute returns true then the checkbox/radiobutton will be checked otherwise it will be unchecked.
Syntax:
<input type="checkbox|radio" ng-checked="expression"> Contents... </input>
If expression returns true then the element’s checked attribute will be checked.
Example: This example uses ng-checked Directive to select checkbox and return the all selected checkbox value.
<!DOCTYPE html> <html> <head> <title>ng-checked Directive</title> <script src= </script> </head> <body ng-app="app"> <div ng-controller="geek"> <h1 style="color:green">GeeksforGeeks</h1> <h2>ng-checked Directive</h2> <input type="checkbox" ng-checked="check1 && check2 && check3 && check4 && check5" ng-model="isChecked" /><b>Select All</b><br> <input type="checkbox" ng-model="check1" ng-checked="isChecked" />First<br> <input type="checkbox" ng-model="check2" ng-checked="isChecked" />Second<br> <input type="checkbox" ng-model="check3" ng-checked="isChecked" />Three<br> <input type="checkbox" ng-model="check4" ng-checked="isChecked" /> Four<br> <input type="checkbox" ng-model="check5" ng-checked="isChecked" />Five<br><br> <b>isAllSelected = {{isChecked}}</b> </div> <script> var app = angular.module("app", []); app.controller('geek', ['$scope', function ($scope) { }]); </script> </body> </html> |
Output:
Before clicking the checkbox:

After clicking the checkbox (select all):

Recommended Posts:
- AngularJS | ng-csp Directive
- AngularJS | ng-app Directive
- AngularJS | ng-value Directive
- AngularJS | Directive
- AngularJS | ng-if Directive
- AngularJS | ng-src Directive
- AngularJS | ng-jq Directive
- AngularJS | ng-cut Directive
- AngularJS | ng-selected Directive
- AngularJS | ng-options Directive
- AngularJS | ng-readonly Directive
- AngularJS | ng-required Directive
- AngularJS | ng-open Directive
- AngularJS | ng-blur Directive
- AngularJS | ng-bind Directive
- AngularJS | ng-change Directive
- AngularJS | ng-non-bindable Directive
- AngularJS | ng-paste Directive
- AngularJS | ng-class-even Directive
- AngularJS | ng-class-odd Directive
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

