AngularJS — Data Binding
One-Way Binding
<p>{{name}}</p>
<input type="text" value="{{name}}">
Two-Way Binding
<input ng-model="name">
<p>Hello, {{name}}!</p>
ng-model Usage
<!-- Text input -->
<input ng-model="user.name">
<!-- Checkbox -->
<input type="checkbox" ng-model="user.active">
<!-- Radio -->
<input type="radio" ng-model="user.gender" value="male"> Male
<input type="radio" ng-model="user.gender" value="female"> Female
<!-- Select -->
<select ng-model="user.country">
<option value="USA">USA</option>
<option value="UK">UK</option>
</select>
Binding in Controllers
app.controller('UserController', function($scope) {
$scope.user = {
name: 'John',
email: 'john@example.com'
};
});
Binding with Expressions
<p>{{user.name | uppercase}}</p>
<p>{{user.name.length}}</p>
<p>{{5 + 5}}</p>
One-Time Binding
<p>{{::name}}</p>
Mini Practice
- Implement one-way binding
- Use ng-model for two-way binding
- Bind different input types
- Use one-time binding
Up Next
Continue with Directives — AngularJS directives.
Related Topics
Frequently Asked Questions about Data Binding
What is Data Binding in AngularJS?
Data Binding is a fundamental concept in AngularJS. This lesson explains it step by step with clear examples, making it easy for beginners to understand.
How do I learn Data Binding?
Start by reading the explanation above, then try the code examples. Practice by modifying the examples and experimenting with different values. Hands-on practice is the best way to learn Data Binding.
Why is Data Binding important in AngularJS?
Data Binding is essential for AngularJS development. Understanding this concept will help you write better code and solve real-world problems more effectively.