Search⌘ K
AI Features

Binding the Data

Explore various data binding methods in Angular such as interpolation, property binding, event binding, and two-way binding. This lesson helps you connect component class data to templates and handle user input efficiently using Angular directives like ngModel. Learn how to apply these techniques to create interactive and dynamic UI elements within Angular applications.

In this lesson, we will learn the concept of binding the data onto the template of a component. You now know what components are and about the following 4 files that are generated when a component is created:

  • TypeScript class file
  • HTML file
  • Styling file (CSS/SCSS/LESS)
  • Spec File (Unit tests)

In the TypeScript code of our component, we would have some data that is supposed to be displayed on the view. This is known as binding the data from the component class to the component template.

There are different ways of binding the data that is either defined locally in your component or is received as a response from an API.

Data Binding techniques

In this section, we will look at the following data binding techniques along with examples.

  • Interpolation
  • Property binding
  • Event binding
  • Two-way data binding

Let us discuss each of these one by one and with examples.

Interpolation

Interpolation is used to bind the value of a variable defined in the component class to a UI element. To interpolate a piece of data, simply put the elements ...