Skip to main content

Command Palette

Search for a command to run...

Bindings in Angular

Updated
•2 min read•View as Markdown
Bindings in Angular
S

Software Engineer with 6+ years of experience in designing and developing web applications. Having experience in ASP.NET Core, Azure, .NET, ASP.NET API, Nodejs, JavaScript, Angular and SQL Server. Currently focused on learning architecture and improving my cloud skills.

Bindings in Angular are a way to connect the data in your Angular application to the HTML template. It enables seamless communication and synchronization between components and their templates.

Types of bindings in Angular:

  • Interpolation: It is denoted by double curly braces {{}} and allows you to embed component data directly into the template. It is primarily used for one-way binding to display dynamic values in the HTML.

      <h1>{{ name }}</h1>
    
  • Property binding: It is denoted by square brackets [] and it allows you to bind the value of an HTML element's property to a value in your application.

      <button type="button" [disabled]="isDisabled">Button</button>
    
  • Event binding: It is denoted by parentheses() and it allows you to bind an event handler to an HTML element's event.

      <button (click)="onButtonClick()">Click me!</button>
    
  • Two-Way Binding: Two-way binding uses the combination of square brackets and parentheses [()] and establishes a bidirectional flow between the component and the template. It allows changes in either the component or the template to be reflected in the other.

      <input type="text" [(ngModel)]="inputText" />
    

How do bindings work?

Angular bindings work using the Angular Change Detection algorithm. This algorithm detects data changes within the application and updates the UI accordingly.

Angular creates a binding expression when you bind a value to an HTML element. This expression is evaluated each time the angle change detection algorithm is run. When the expression value changes, the UI updates to reflect the new value.

Why use bindings in Angular?

Bindings are a powerful way to connect the data in your Angular application to the HTML template. They allow you to dynamically update the UI based on the data in your application, which makes your application more responsive and interactive.

Bindings are also a great way to decouple your application's data from its presentation. This makes your application easier to test and maintain.

More from this blog

.NET - Sankarshan Ramesh

22 posts

The blog entries serve as my comprehensive annotations on the respective topics during my learning process.