Sunday, 31 July 2016

Two-Way Data Binding in agnularJs


Data-binding in Angular apps is the automatic synchronization of data between the model and view components.
Data binding lets you treat the model as the single-source-of-truth in your application. The view is a projection of the model at all times. If the model is changed, the view reflects the change and vice versa.
----------------------------
<!DOCTYPE html>  
<html>  
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>  
<body>  
<div data-ng-app="" data-ng-init="quantity=1;price=20">  
<h2>Cost Calculator</h2>  
Quantity: <input type="number" ng-model="quantity">  
Price: <input type="number" ng-model="price">  
<p><b>Total in rupees:</b> {{quantity * price}}</p>  
</div>  
</body>  
</html>  
----------------- 
Output:- if you will run above code you will get two number boxes and once you will set the value of quantity and price you will get output based on input number like below.

Total in rupees: 20