Welcome back to the Learn Angular 8 in 10 Days article series - Part 3. In the previous article, we discussed the basic concept of Components. Now, in this article, we will discuss the Concept of Data Binding. If you want to read the previous articles of this series, then follow the links.
So, in this article, we will discuss the concept of Data Binding in Angular 8. Data Binding is one of the most important features of the Angular framework. This is because, at any web-based application, data pushing and pulling is always performed a key role in the development. In Angular, this can be done with the help of the Data Binding concept very easily.
What is data binding?
Data binding is one of the finest and most useful features of the Angular framework. Due to this feature, the developer needs to write less code compared to any other client-side library or framework. Data binding in an Angular application is the automatic synchronization of data between the model and view components. In Angular, we can always treat the model as a single source of truth of data in our web application with the data binding. In this way, the UI or the view always represents the data model at all times. With the help of data binding, developers can establish a relationship between the application UI and business logic. If we establish the data binding correctly, and the data provides the proper notifications to the framework, then, when the user makes any data changes in the view, the elements that are bound to the data reflect changes automatically.
The basic concept of data binding
In the case of any web-based application development, we always need to develop a connection bridge between the back end, where data is stored, and the front end or user interface through which user performs their application data manipulation. Now, this entire process always depends on consecutive networking interactions and repetitive communication between the server (i.e. back end) and the client (i.e. front end).
Due to the consecutive and repetitive communication between client and server, most web framework platforms focus on one-way data binding. This involves reading the input from the DOM, serializing the data, sending it to the back end or server, and waiting for the process to finish. After that, the process modifies the DOM to indicate if any errors occurred or reloads the DOM element if the call is successful. While this process provides a traditional web application all the time it needs to perform data processing, this benefit is only applicable to web apps with highly complex data structures. If your application has a simpler data structure format, with relatively flat models, then the extra work can needlessly complicate the process and decrease the performance of your application.

The angular framework addresses this with the data binding concept. Data binding provides a continuous data upgradation process so that when the user makes any changes in the interface it will automatically update the data and vice-versa. In this way, the data model of the application always acts as an atomic unit so that the view of the application can be always updated concerning the data. This process can be done with the help of a complex series of event handlers and event listeners in many frameworks. But that approach can be fragile very quickly. In Angular Framework, this process related to the data becomes one of the primary parts of its architecture. Instead of creating a series of call-backs to handle the changing data, Angular does this automatically without any needed intervention by the programmer. This feature is a great relief for the programmer and reduces much more development time.
So, the first and foremost advantage of data binding is that it updates the data models automatically concerning the view. So, when the data model updates, that will automatically update the related view element in the application. In this way, angular provides us with a correct data encapsulation on the front end and it also reduces the requirement to perform complex and destructive manipulation of the DOM elements.
Why is data binding required?
From day one, the Angular framework provides this special and powerful feature called Data Binding which always brings smoothness and flexibility to any web application. With the help of data binding, developers can gain better control over the process and steps that are related to the data binding process. This process makes the developer's life easier and reduces development time concerning other frameworks. Some of the reasons related to why data binding is required for any web-based application are listed below.
- With the help of data binding, data-based web pages can be developed quickly and efficiently.
- We always get the desired result with a small volume of coding size.
- Due to this process, the execution time increases. As a result, it improves the quality of the application.
- With the help of an event emitter, we can achieve better control over the data binding process.
Different types of data binding
In Angular 8, there are four different types of Data binding processes available. They are
- Interpolation
- Property Binding
- Two-Way Binding
- Event Binding
Interpolation
Interpolation data binding is the most popular and easiest way of data binding in Angular 8. This feature is also available in previous Angular framework versions. The context between the braces is the template expression that Angular first evaluates and then converts into strings. Interpolation uses the braces expression i.e. {{ }} to render the bound value to the component template. It can be a static string, a numeric value, or an object of your data model. In Angular, we use it like this: {{firstName}}. The below example shows how we can use the interpolation in the component to display data in the front end.
<div>
<span>User Name : {{userName}}</span>
</div>
Property-based binding
In Angular 8, another binding mechanism exists, which is called Property Binding. In nature, it is just the same as interpolation. Some people also called this process as one-way binding like the previous AngularJS concept. Property binding is used [] to send the data from the component to the HTML template. The most common way to use property binding is to assign any property of the HTML element tag into the [] with the component property value, i.e.
<input type="text" [value]="data.name" />
To implement the property binding, we will just make the below changes in the previous HTML file from the interpolation sample i.e. interpolation.component.html.
<div>
<input [value]="value1" />
<br /><br />
</div>
Event binding
Event binding is another of the data binding techniques available in Angular. This data binding technique does not work with the value of the UI elements—it works with the event activities of the UI elements like click-event, blur-event, etc. In the previous version of AngularJS, we always used different types of directives like ng-click, and ng-blur to bind any particular event action of an HTML control. But in the current Angular version, we need to use the same property of the HTML element (like click, change, etc.) and use it within parentheses. In Angular 8, for properties, we use square brackets, and in events, we use parentheses.
<div>
<input type="submit" value="Submit" (click)="fnSubmit()">
</div>
Two-way data binding
In Angular Framework, the most used and important data binding techniques are known as Two-Way Data Binding. Two-way binding is mainly used in the input type field or any form element where the user can provide input values from the browser or provide any value or change any control value through the browser. On the other side, the same is automatically updated into the component variables and vice versa. Similarly, in Angular 8 we have a directive called ngModel, and it needs to be used as below.
<input type="text" [(ngModel)]="firstName"/>
We use [] since it is a property binding, and parentheses are used for the event binding concept i.e. the notation of two-way data binding is [()].

ngModel performs both property binding and event binding. The property binding of the ngModel (i.e. [ngModel]) performs the activity to update the input element with a value. Whereas (ngModel) ( (ngModelChange) event) instructs the outside world when any change occurs in the DOM Element.
The below example demonstrates the implementation of two-way binding. In this example, we define a string variable called strName and assign that variable with a Textbox control. So, whenever we change any content in the textbox, the value of the variable will be changed automatically.
<div>
<input [(ngModel)]="strName" type="text"/>
</div>
@Input() decorator
In Angular Framework, every component is used either as a stateless component or a stateful component. Normally, the components are used in a stateless way. But sometimes we need to use some stateful components. The reason behind using a stateful component in a web application is due to the data passing or receiving from the current component to either a parent component or a child component. So, in this way, we need to inform Angular what type of data or which data may come to our current component. To implement this concept, we need to use the @Input() decorator against any variable. The key features of the @Input() decorator are as follows.
- @Input is a decorator to mark an input property. With the help of this property, we can define an input parameter property just like normal HTML tag attributes to pass and bind that value into the component as a property binding.
- @Input decorator always provides one-way data communications from the parent component to the child component. Using this feature, we can provide some of the value against any property of a child component from the parent components.
- The component property should be annotated with the @Input decorator to act as an input property. A component can receive value from another component using component property binding.







Dalibor ŠkorićPosted Oct 27, 2022, 1:38 PM
The end was complicated, but thanks anyway. This Angular logic of two way binding and INPUT/OUTPUT looks on first look like they had idea when they made it: "Why make it simple, when it could be complicated and unintuitive, and who understands - will be very proud on himself. " I had some professors on a faculty who explained things in a complicated way to look like bigger experts, so Angular makers look to me like that now, but I am probably wrong.
J KPosted Jun 7, 2020, 9:11 PM
Thank you sir, u r amezing..
Robin HaiderPosted Nov 21, 2019, 10:56 AM
Thank you, Sir
Hamid KhanPosted Sep 20, 2019, 7:05 AM
Good article, you may add all in one pdf book
Salman ShaikhPosted Sep 17, 2019, 3:45 AM
Thank you sir for this easy to understand article :) , Learned a lot from Day 1 , Day 2 and Day 3 looking forward for more articles.!!
phuong caoPosted Sep 10, 2019, 1:52 AM
The article is very helpful. Hope the "Day 3" will coming soon
vinay kumarPosted Sep 4, 2019, 1:07 PM
Really nice article......... But i am unable to seen angular 8 from day4-day10. Please do needful.
vinay kumarPosted Sep 4, 2019, 1:07 PM
Hi Debasis saha,
Chu DuPosted Sep 3, 2019, 3:57 AM
Thank You.
Amit MohantyPosted Sep 2, 2019, 11:30 PM
Nicely described.
Rajdeep SahaPosted Sep 1, 2019, 9:03 PM
Thank u sir for sharing this very useful article. It helps me a lot to understanding Angular 8. Awaiting for the next part of the series.