ITZone

Angular stripes – Properties binding and Interpolation

In this article, I will send to everyone an extremely useful feature in Angular that we use very often, that is properties binding . So what is it?

P / s: The article is referenced from the source .

Understanding data binding types in Angular is an important step in building an Angular application. When building, you will often meet the duo specializing in displaying data in the view: Properties binding and Interpolation – supporting transferring data from component to view .

Data binding is an important and powerful technique in application development. It supports interaction between component and its own view. Help our application become more flexible.

Well, long theory is enough. The main part is always, in Angular there are 4 main types of data binding:

  1. Event binding
  2. Two-way data binding
  3. Interpolation
  4. Property binding

The first is Event binding : this form will trigger the event from view to component . The view will send data from an event, for example when we click the button to update the value in the component. This is the opposite of property binding – from component to view .
See the details in the following example:

Next, we will learn about Two-way data binding : with this type of binding, the data flow will go 2-way from component to view and vice versa. Components and views will be synchronized immediately when there is a change from 1 in 2 sides. This format is often used in the form to update the value as the user enters it.

Interpolation
This form will be covered in this section. In this technique, the variable represented in the component is placed between the curly brace of the view. Angular will find the variable that matches the text in our view and replace this text with the value that is assigned to the variable . Numeric and string distortions are placed between {{}} pairs.

Property binding This binding mechanism helps you set properties for elements in the view. Update the value of an attribute in the view and bind it to an element. Syntax: [] . The following is an example of setting the disabled property via property binding for a button:

The following article, we will learn more details about String Interpolation as well as examples of Property binding or more here .

Share the news now