The
ng-checked directive is used with
checkbox controls to set the checkbox status to checked/un-checked. The status
of the checkbox can be controlled from a variable/property in the model object,
just set the model property value to the ng-checked directive and the checkbox
will automatically change its state based on the value of the property.
In the following example the $scope.checkedStatus property controls the state of the checkbox control.
<html ng-app="changeCheckboxApp">
<head>
<meta charset="utf-8">
<title>AngularJS - Basic</title>
<script src="angular.min.js"></script>
<script>
var app = angular.module('changeCheckboxApp', []);
function changeCheckboxController($scope) {
$scope.checkedStatus = true;
};
</script>
</head>
<body>
<div ng-controller="changeCheckboxController">
Checked Status: {{checkedStatus}} <input type="checkbox" ng-model="checkedFlag" ng-checked="checkedStatus"> <br/><br/>
</div>
</div>
</body>
</html>
Output
In the following example the $scope.checkedStatus property controls the state of the checkbox control.
<html ng-app="changeCheckboxApp">
<head>
<meta charset="utf-8">
<title>AngularJS - Basic</title>
<script src="angular.min.js"></script>
<script>
var app = angular.module('changeCheckboxApp', []);
function changeCheckboxController($scope) {
$scope.checkedStatus = true;
};
</script>
</head>
<body>
<div ng-controller="changeCheckboxController">
Checked Status: {{checkedStatus}} <input type="checkbox" ng-model="checkedFlag" ng-checked="checkedStatus"> <br/><br/>
</div>
</div>
</body>
</html>
Output
No comments:
Post a Comment