Knowledge Management Banner

Knowledge Management Banner

$watch in angularjs

$watch is used to monitor change in model variables.

HTML Code

 <script src="angular.1.4.8.min.js"></script>  
 <div ng-app="MyApp">  
   <div ng-controller="MyController">  
     <style type="text/css">  
       table#DemoTable, #DemoTable td, #DemoTable th {  
         border-collapse: collapse;  
         border: 1px solid red;  
         padding: 5px;  
         font-family: Calibri;  
       }  
     </style>  
     <h1>{{Title}}</h1>  
     <hr />  
     <table id="">  
       <tr>  
         <th>First Name</th><td><input float-box ng-model="Name" type="text" /></td>  
       </tr>  
     </table>  
     <hr />  
   </div>  
 </div>  
 <script src="index.js"></script>  

AngularJS Code

 /// <reference path="angular.1.4.8.min.js" />  
 var ngapp = angular.module("MyApp", []);  
 ngapp.controller("MyController", function ($scope) {  
   $scope.Title = "$Watch";  
   $scope.Name = "Hello World ! . . .";  
   $scope.$watch("Name", function (newvalue, oldvalue) {  
     alert(oldvalue);  
   })  
 });  

No comments

Powered by Blogger.