Saturday, March 14, 2015

ng-checked directive

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



Search Flipkart Products:
Flipkart.com

No comments: