by 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 2021 (Beginner + Advanced)
JavaScript - The Complete Guide 2021 (Beginner + Advanced)
64,026 students enrolled
52 hours of video content
View Course
React - The Complete Guide (incl Hooks, React Router, Redux)
React - The Complete Guide (incl Hooks, React Router, Redux)
284,472 students enrolled
40 hours of video content
View Course
Vue - The Complete Guide (w/ Router, Vuex, Composition API)
Vue - The Complete Guide (w/ Router, Vuex, Composition API)
152,857 students enrolled
48.5 hours of video content
View Course