One of the important features of AngularJS is Data Binding, which is a concept used to bind UI related items with the programing variables
/objects.
UI will update automatically, whenever the programing items are updated.
AngularJS supports two types of Bindings, which are-
1. One-way Binding
In One way Binding, UI will get the updated values, whenever you modify the variables. In this Binding, only reading the value from the variables and updates in UI takes place. UI cannot update the value of the variables.
It can be implemented, using AngularJS expressions (or) ng-bind.
Ex - <span>{{X}}</span>
Example For One way Binding
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head runat="server">
- <title></title>
- <script src="scripts/angular.min.js">
-
- </script>
- </head>
- <body>
- <form id="form1" runat="server">
- <div ng-app="" ng-init="x='maya'">
- UserName:<input type="text"/>
- <span>welcome to {{x}}</span>
- </div>
- </form>
- </body>
- </html>
2. Two-wayBinding
In Two-way Binding , HTML controls are bound with the variables. If you update the variable, it will reflect in the controls. If you update the control value, it will be reflected in the variable. It can be implemented, using "ng-model" directive.
Ex -<input type="text" ng-model="X"/>
Example for Two -way Binding
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head runat="server">
- <title></title>
- <script src="scripts/angular.min.js">
-
- </script>
- </head>
- <body>
- <form id="form1" runat="server">
- <div ng-app="" ng-init="x='maya'">
- UserName:<input type="text" ng-model="x" />
- <span>welcome to {{x}}</span>
- </div>
- </form>
- </body>
- </html>