Tutorial 8 - ng-true-value and ng-false-value in AngularJS

How to use ng-true-value and ng-false-value in AngularJS?
Following is sample to help you know how to use ng-true-value and ng-false-value in input via checkbox type.




 <html>  
 <head>  
   <title> </title>  
   <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.2/angular.min.js"></script>  
   <script>  
   <style>  
     .ng-invalid {  
       color: red;  
     }  
     td {  
       padding-right: 30px;  
     }  
   </style>  
   <script>  
     angular.module('myapp', [])  
         .controller('ExampleController', ['$scope', function ($scope) {  
           $scope.game = 'NO';  
           $scope.tour = 'YES';  
         }]);  
   </script>  
 </head>  
 <body ng-app="MyForm"   
   <form name="calForm" ng-controller="ExampleController" ng-submit=" DoAction()">  
     <br /  
     Play game: <input type="checkbox" ng-model="game"  
     ng-true-value="'YES'" ng-false-value="'NO'" />          
     <br />  
     Tour: <input type="checkbox" ng-model="tour" ng-true-value="'YES'"   
     ng-false-value="'NO'" />   
     <br />  
     <h4>you are choosing</h4>  
     <tt>Play game = {{game}}</tt><br />  
     <tt>Tour = {{tour}}</tt><br />  
   </form>  
 </body>  
 </html>  


2 comments:

Popular Posts