Watch checkbox value

Description

The following code shows how to watch checkbox value.

Example


<!DOCTYPE html>
<html  ng-app>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.13/angular.js"></script>
<script type='text/javascript'>
<!--  www.  ja va 2 s .  c om-->
function MyCtrl($scope) {
    $scope.$watch(
      function() {
        return $scope.master + $scope.slave; 
      },function() {
        $scope.slave = $scope.master;
    });
}
</script>
</head>
<body>
  <div ng-app="" ng-controller="MyCtrl">
  Check me to check both:
    <input type="checkbox" ng-model="master"><br/>
    <input type="checkbox" ng-model="slave" ng-checked="master">
</div>
</body>
</html>

Click to view the demo





















Home »
  AngularJS »
    AngularJS Example »




Controller
Directives
Expression
Filter
Form
Inject
Scope
Server
Style
Template
Utilities