AngularJS Tutorial - ng-true-value sets true value for checkbox








The following code shows how to use ng-true-value to set true value for checkbox.

Example


<!DOCTYPE html>
<html  ng-app>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.13/angular.js"></script>
</head><!-- ww w.j ava  2  s  .  c  o  m-->
<body>
  <label class="checkbox">
  <input type="checkbox" 
         ng-model="user.role" 
         ng-true-value="admin" 
         ng-false-value="basic"> Is Administrator</label>
  
  <pre ng-bind="user | json"></pre>
</body>
</html>

The code above is rendered as follows: