What is data binding? Explain the four types.
Model answer
Data binding connects the component class and the template. The types are:
Interpolation, {{ value }}, shows a value as text. Property binding, [property]="value", sets an element or component property. Event binding, (event)="handler()", runs a method when something happens, such as a click. Two-way binding, [(ngModel)]="value", keeps a field and a variable in sync in both directions.
Signal-based model() inputs also support two-way binding between a parent and a child component.
Tips
- Give a one-line example of each.
Learn this topic
Angular Tutorial: Beginner to Advanced .
Sign in to add your own answer.
More questions
- What are the parts of a component?
- What is the difference between interpolation and property binding?
- How do you pass data from a parent component to a child component?
- How does a child component send data to its parent?
- What is the component lifecycle? Describe the main hooks.
- What is the difference between the constructor and ngOnInit?