---
title: "Data Binding in AngularJS"  
description: "Data Binding is one of the most powerful and commonly used features in AngularJS. It provides a way to synchronize the data between the model and the"  
author: "Ravi Vishwakarma"  
published: 2024-06-24  
updated: 2024-06-24  
canonical: https://www.mindstick.com/blog/304414/data-binding-in-angularjs  
category: "angular js"  
tags: ["web development", "angular js", "front-end development"]  
reading_time: 2 minutes  

---

# Data Binding in AngularJS

[**Data Binding**](https://www.mindstick.com/forum/159666/how-exactly-does-data-binding-work-in-angularjs) is one of the most powerful and commonly used [features](https://www.mindstick.com/articles/12993/5-advanced-features-for-your-odoo-ecommerce-theme) in [AngularJS](https://www.mindstick.com/articles/13081/advantages-disadvantages-of-angularjs-is-that-ideal-for-your-project). It provides a way to synchronize the data between the [model](https://yourviews.mindstick.com/view/81334/america-is-reopening-after-corona-lockdown-but-on-swedish-model) and the view. This means that when the data in the model changes, the view reflects that change, and vice versa.

There are two main types of data binding in AngularJS:

1. **One-Way Data Binding**
2. **Two-Way Data Binding**

## One-Way Data Binding

In one-way data binding, the data flows in one [direction](https://yourviews.mindstick.com/story/5034/10-animals-with-the-best-sense-of-direction), either from the model to the view or from the view to the model. This is [useful](https://www.mindstick.com/articles/12694/how-dolomite-mineral-is-useful-in-human-life) when you only need to [display data](https://www.mindstick.com/forum/160249/what-is-the-role-of-the-display-data-annotation-to-display-name-for-a-model-property-in-dot-net-core) without updating the model from the view.

**Model to View**: [Updates](https://yourviews.mindstick.com/view/88503/us-iran-war-live-updates-trump-says-us-in-no-rush-to-end-iran-war) the view whenever the model changes.

```javascript
<div ng-app="myApp" ng-controller="myCtrl">
    <p>{{ message }}</p>
    <p ng-bind="message"></p>
</div>
```

**View to Model**: Updates the model when the view changes, usually through [user input](https://www.mindstick.com/forum/159624/setting-an-enum-from-user-input).

```javascript
<div ng-app="myApp" ng-controller="myCtrl">
    <input type="text" ng-model="message">
</div>
```

## Two-Way Data Binding

In two-way data binding, the data flows in both directions. Changes in the model [update](https://www.mindstick.com/forum/265/ajax-update-panel) the view, and changes in the view update the model. This is achieved using the `ng-model` directive.

```javascript
<div ng-app="myApp" ng-controller="myCtrl">
    <input type="text" ng-model="message">
    <p>{{ message }}</p>
</div>
```

## Example -

```javascript
<!DOCTYPE html>
<html>
<head>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.8.2/angular.min.js"></script>
    <script>
        // Define the module
        var app = angular.module('myApp', []);

        // Define the controller
        app.controller('myCtrl', function($scope) {
            $scope.message = 'Hello, AngularJS!';
            $scope.updateMessage = function(newMessage) {
                $scope.message = newMessage;
            };
        });
    </script>
</head>
<body ng-app="myApp">

    <div ng-controller="myCtrl">
        <h2>One-Way Data Binding</h2>
        <p>{{ message }}</p>
        <p ng-bind="message"></p>

        <h2>Two-Way Data Binding</h2>
        <input type="text" ng-model="message">
        <p>{{ message }}</p>

        <h2>Updating Model from View</h2>
        <input type="text" ng-model="newMessage">
        <button ng-click="updateMessage(newMessage)">Update Message</button>
    </div>

</body>
</html>
```

---

Original Source: https://www.mindstick.com/blog/304414/data-binding-in-angularjs

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
