Author -  Sai gowtham

Difference Between One-way and Two-way Databinding in Angular

In this tutorial, we are going to learn about what is the difference between one way data binding and two-way data binding in angular.

What is DataBinding?

DataBinding means connecting the data to the view or UI, it means the data we defined inside our component is attached to the HTML template.

One-way data binding

One-way data-binding means the data flows in a single direction so that whenever the data changes in a component, it also updates the view with new data.

Example:

angular one-way-databinding

Have you seen in the above image the data property we defined inside the app.component.ts file is connected to the html template by using {{}} syntax.

Now if we change the title property inside app.component.ts file our view also updates with the new change this is called one-way data binding.

Two-way data binding

Two-way data binding means data flows in both directions, it means any change happens in the view updates the data and any change happens in the data updates the view.

In angular, by using ngModel directive we can create two-way data binding.

Example:

angular-two-way-data-binding

In the above image, we have connected the data property title to the input element by using ngModel directive.

Now, if we change the <input> element value in the view it updates the title property.similarly, if we change the title property inside the component file it also the updates the <input> element value.

Css Tutorials & Demos

How rotate an image continuously in CSS

In this demo, we are going to learn about how to rotate an image continuously using the css animations.

How to create a Instagram login Page

In this demo, i will show you how to create a instagram login page using html and css.

How to create a pulse animation in CSS

In this demo, i will show you how to create a pulse animation using css.

Creating a snowfall animation using css and JavaScript

In this demo, i will show you how to create a snow fall animation using css and JavaScript.

Top Udemy Courses

JavaScript - The Complete Guide 2023 (Beginner + Advanced)
JavaScript - The Complete Guide 2023 (Beginner + Advanced)
116,648 students enrolled
52 hours of video content
$14.99 FROM UDEMY
React - The Complete Guide (incl Hooks, React Router, Redux)
React - The Complete Guide (incl Hooks, React Router, Redux)
631,582 students enrolled
49 hours of video content
$24.99 FROM UDEMY
Vue - The Complete Guide (w/ Router, Vuex, Composition API)
Vue - The Complete Guide (w/ Router, Vuex, Composition API)
203,937 students enrolled
31.5 hours of video content
$14.99 FROM UDEMY