Sobes.tech
Middle

What types of data binding exist in Angular?

sobes.tech AI

Answer from AI

In Angular, the following data binding types exist:

  1. One-Way Data Binding: Component to DOM: Changes in the component are reflected in the view (HTML).

    • Interpolation Binding: Displaying component property values.

      <p>{{ componentProperty }}</p>
      
    • Property Binding: Setting DOM element property values.

      <img [src]="imageUrl">
      
  2. One-Way Data Binding: DOM to Component: Changes in the view (user events) affect component properties.

    • Event Binding: Handling DOM element events.

      <button (click)="handleClick()">Click me</button>
      
  3. Two-Way Data Binding: Changes in the component and view affect each other simultaneously.

    • Uses the [()] syntax.

      <input [(ngModel)]="userName">
      
    • Requires importing FormsModule for ngModel.