AngularJS ng-checked Directive

Definition and Usage

ng-checked directive is used to set the checked attribute of checkboxes or radio buttons.

If ng-checked if the expression in the attribute returns true, the checkbox or radio button is selected.

ng-checked The directive is used for true and false it is necessary to switch the value between checked The attribute is set to falseThe presence of the checked attribute selects the element, regardless of its value.

Example

Select one to select all:

<body ng-app="">
<p>My Car:</p>
<input type="checkbox" ng-model="all"> Select All<br><br>
<input type="checkbox" ng-checked="all">Volvo<br>
<input type="checkbox" ng-checked="all">Ford<br>
<input type="checkbox" ng-checked="all">Mercedes
</body>

Try It Yourself

Syntax

<input type="checkbox|radio" ng-checked="expression</input>

by checkboxes or radio types <input> Elements Supported.

Parameters

Parameters Description
expression Expression, if it returns true, then the checked attribute of the element is set.