AngularJS Tutorial - Control a checkbox through value in scope








You can control a checkbox through value in scope.

Example


<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.13/angular.js"></script>
</head><!--from   w  w  w  .  j  a  v  a 2s  .c  o m-->
<body>
  <div ng-app ng-controller="x">
     <input type="checkbox" ng-checked="y"> {{y}}
  </div>
<script type='text/javascript'>
function x($scope) {
    $scope.y = 1;
}
</script>
</body>
</html>

The code above is rendered as follows: