![]() |
VOOZH | about |
Data Binding is a technique used to automatically synchronize data between the model and view components. Angular supports both one-way and two-way data binding, making the code more loosely coupled and easier to manage.
Data binding can be categorized into 2 types:
One-way Binding | Two-way Binding |
|---|---|
In one-way binding, the flow is one-directional. | In a two-way binding, the flow is two-directional. |
This means that the flow of code is from TypeScript file to the HTML file. | This means that the flow of code is from TypeScript file to HTML file as well as from HTML file to TypeScript file. |
In order to achieve one-way binding, we used the property binding concept in Angular. | In order to achieve a two-way binding, we will use ngModel or banana in a box syntax. |
In property binding, we encapsulate the variable in HTML with square brackets( [ ] ). | Import |
Changes in the view are not reflected back in the component class. | Changes in the view update the component, and component changes update the view. |
Uses property binding only. | Uses |
Used when data needs to flow only from the component to the view. The general use cases are:
@Input(). Output:
👁 ImageUsed when data in the component and view must stay synchronized. The general use cases are:
Output:
👁 Image