AngularJS - Checkbox with default value

In the following example, we set the values for our checkbox using ng-checked. The default values are set using ng-init; the same result is accomplished by initializing the value in the controller. When the user marks the checkbox as checked, we use the ng-click to change the value from true to false, or vice versa.

<div ng-init="options={};options.one.selected=true">
    <input id="option_1" type="checkbox" 
        ng-click="options.one.selected=!options.one.selected"
        ng-checked="options.one.selected"
        ng-model="options.one.selected"/>
    <label for="option_1" >Option 1</label>
</div>

Note: ng-checked expects an expression.

For more information go to the AngularJS documentation

comments powered by Disqus