Angular Components And Data Binding Techniques
Tags: angular, databinding
Published: 2020-07-15 09:34:32

---
title: Angular Components And Data Binding Techniques
published: true
date: 2020-05-02 21:44:22 UTC
tags: angular,databinding
canonical_url: 
---

In this article, we would like to discuss the Angular component and data binding techniques available in angular.

Angular components are building blocks of Angular application. An angular component represents a custom HTML element that represents a specific section on a page. Angular components always associated with a template.

To make Typescript class as a component, you need to decorate with ‘@component’ metadata decorator. Below is high-level responsibilities segregation in a component

![](https://cdn-images-1.medium.com/max/1024/0*KRvZFX-gT_lmOkwq.png)

**@Component decorator options**

- selector: Defines the name of the HTML element that represents this component in a page
- Template — Holds HTML of the component
- TemplateUrl: Holds the HTML template path
- Providers: Any additional services that a component want to access in addition to the global services
- Encapsulation: Controls how the styling is applied to this component

**Data Binding**

Data binding is the process of connecting a UI element such as textbox or dropdown with the information that populates it. Using this data binding, the information will be passed from source to destination.

In angular terminology, Data binding responsible for coordinating the communication between the component’s class and its templates and often involves the passing the data

There are 4 types of data binding

- Property Binding
- Interpolation
- Event Binding
- Two-way binding

**Property binding**

Property Binding is a data binding technique that will help you to bind the properties of an HTML element with your component’s properties or methods. Property binding is a one-way binding.

```
<button [disabled]="btnDisabled"></button> 
// component.ts 
@Component({ 
selector: 'app-component', 
templateUrl: 'component.html' 
}) 
export class Component { 
btnDisabled = true; 
}
```

![](https://cdn-images-1.medium.com/max/1024/0*90_Lk8xyg8iOqUq6.png)<figcaption>Property Binding</figcaption>

**Interpolation**

Interpolation is a one-way data-binding technique that allows you to bind the component’s class properties to UI elements. it uses double curly braces ( **`{{ your expression or property }}`** ) to display the data from component to view.

<div> `{{greeting}}`</div>

**Event Binding**

In any typical application, a user interacts with the application. As part of user interaction, the user needs to click the buttons or entering the details in text boxes, etc. All these actions come under events. In technical terms, we call them button events, keystrokes, change events, etc.

If you want to send the information from view to component’s class you need to use the event binding. This is also a one-way binding and exactly does the opposite of property binding.

To capture an event from the view, you need to wrap the event inside the parenthesis “()”

<button (click)=”saveDetails()”>Save</button>

**Two-way binding**

The two-way binding combines the **property binding** and **event binding**

![](https://cdn-images-1.medium.com/max/1024/0*dvmIBoPvRacQ85J_.png)

That’s all for today’s topic. Thank you for reading. Please share your thoughts in the comments box.

![](https://cdn-images-1.medium.com/max/72/0*powLFoYX6xfJ4iiq.png)

_Originally published at_ [_http://www.techmonks.org_](http://www.techmonks.org/angular-components/) _on May 2, 2020._

* * *