Hi, My name is Sandeep Kumar and I am a Software Engineer from INDIA.
Connect with me on LinkedIn | WhatsApp me

What is two way data binding in angular js ?

Author: FrontBackGeek | Published Date: January 6, 2022 |   Angular js

Two way data binding keeps the model and view in sync at all times, i.e a change in model, updates the view and a change in view, updates the model.

Binding expressions update the view when model changes.

Let’s understand with code.

<!DOCTYPE html>
    <script src=“https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js”></script>
        var app = angular.module(‘newApp’, []);
        app.controller(‘newCtrl’, function($scope) {
            $scope.name = “John”;
            $scope.age = 25;
<div ng-app=“newApp” ng-controller=“newCtrl”>
 Name: <input type=“text” ng-model=“name”><br>
 Age: <input type=“number” ng-model=“age”><br>
Name: {{name}}<br/>
Age : {{age}}

So in this example when user enter in input field for entering name and age, below those input fields name and age automatically changes and update on UI or view.

So any change inside input field or any change in model, changes the view at same time. Output of this code will show you the result on browser.

This is two way binding in angular js if you like the post please share with your friends.