Two Way Data Binding In AngularJS

In this article, we will learn two-way data binding in AngularJS. In the previous AngularJS articles you may have read the following articles:
What is Two way Data binding in AngularJS

One of the core feature of AngularJS which makes it popular is two way data binding. In two way data binding, any changes to the model are immediately reflected in the View and any changes in the View updates the model.
  1. <!DOCTYPE html>  
  2. <html xmlns="">  
  4. <head>  
  5.     <title></title>  
  6.     <script src="Script/angular.js"></script>  
  7.     <script type="text/javascript">  
  8.         var myApp = angular.module('myApp', [])  
  9.             .controller('myController', function($scope) {  
  10.                 $ = "Anoop";  
  11.             });  
  12.     </script>  
  13. </head>  
  15. <body ng-app="myApp">  
  16.     <div ng-controller="myController">  
  17.         Enter Name:<input type="text" ng-model="name" />  
  18.         <p>Hello! {{name}}  
  19.     </div>  
  20. </body>  
  22. </html>  
In above code, we have created a controller (i.e. myController) and registered it with myApp module. We used ng-model property for displaying the value of HTML control with the help of {{name}} Template. If we change the value in Textbox then it will update the model or if we change the value of model then it will immediately update the View.

I hope you like it.Thanks.

Similar Articles