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"> <label for="option_1" >Option 1</label> </div>
Note: ng-checked expects an expression and it does not work with ng-model in the same element.
Useful links:
Working Example: Plunkr
Angularjs Online Training Angularjs Training Angularjs Training Angularjs Training in Chennai Angularjs Training in Chennai Angularjs Course Angularjs Course Angular 2 Training in Chennai
ReplyDelete