Data Binding
Data Binding Interview with follow-up questions
1. What is data binding in Angular?
Data binding connects a component's class and its template so you describe the UI declaratively instead of manipulating the DOM by hand. Data can flow class → view (display state), view → class (respond to events), or both ways.
The four syntaxes:
- Interpolation —
{{ expr }}(text/content). - Property binding —
[prop]="expr"(class → view). - Event binding —
(event)="handler()"(view → class). - Two-way binding —
[(ngModel)]="x"/[(value)]="x"(both).
The modern framing that signals current knowledge: what binding triggers has shifted. Classic Angular re-checked bindings via Zone.js-driven change detection; modern Angular drives updates with signals and zoneless change detection (default in new v21+ apps), so reading a signal() in a binding updates exactly the views that depend on it. Conceptually it's still data binding — the reactivity underneath is just finer-grained.
Follow-up 1
Can you differentiate between one-way and two-way data binding?
One-way data binding is a unidirectional flow of data, where changes in the model are reflected in the view, but changes in the view do not affect the model. It is denoted by square brackets [] in Angular.
Two-way data binding, on the other hand, allows for bidirectional flow of data, where changes in the model are reflected in the view and vice versa. It is denoted by square brackets and parentheses [()].
Follow-up 2
What is the significance of data binding in Angular?
Data binding is a key feature in Angular as it simplifies the development process by reducing the amount of code needed to manually update the view and handle user input. It helps in keeping the model and view in sync, making it easier to build dynamic and interactive web applications.
Follow-up 3
Can you provide a simple example of data binding in Angular?
Sure! Here's a simple example of one-way data binding in Angular:
In the component class:
export class AppComponent {
message: string = 'Hello, World!';
}
In the template:
<p>{{ message }}</p>
The value of the message property in the component class is bound to the {{ message }} expression in the template, so any changes to the message property will be automatically reflected in the view.
And here's an example of two-way data binding:
In the component class:
export class AppComponent {
name: string = 'John Doe';
}
In the template:
<p>Hello, {{ name }}!</p>
The [(ngModel)] directive binds the value of the name property in the component class to the input field, so any changes in the input field will update the name property and vice versa.
2. What are the different types of data binding in Angular?
Angular's binding is usually described as four types (the source's "three" omits interpolation):
- Interpolation —
{{ value }}, renders data as text (class → view). - Property binding —
[src]="url", sets element/component/directive properties (class → view). - Event binding —
(click)="save()", responds to events (view → class). - Two-way binding —
[(ngModel)]="name"(the "banana in a box"), which is just property binding + event binding combined.
By direction there are three flows (one-way down, one-way up, two-way), which is why some sources say "three." Related one-way variants worth naming: attribute ([attr.aria-label]), class ([class.active]), and style ([style.width.px]) bindings.
A current note: any custom component can be made two-way-bindable with the model() signal API, giving [(prop)] support without ngModel — the idiomatic modern way to do two-way binding on your own components.
Follow-up 1
Can you explain how property binding works?
Property binding in Angular allows you to set the value of a property of a DOM element or a directive. It is denoted by square brackets [] and is used to bind a property of a DOM element to a value in the component's class.
For example, let's say you have a component with a property called 'name' in its class. You can bind this property to the value of an input element using property binding as follows:
In this example, the value of the 'name' property in the component's class will be set as the initial value of the input element. If the value of the 'name' property changes in the component's class, the value of the input element will also be updated automatically.
Follow-up 2
How does event binding differ from property binding?
Event binding in Angular allows you to listen to events emitted by DOM elements or directives and perform actions in response to those events. It is denoted by parentheses () and is used to bind an event of a DOM element to a method in the component's class.
Unlike property binding, which sets the value of a property of a DOM element or a directive, event binding triggers a method in the component's class when a specific event occurs.
For example, let's say you have a button element and a method called 'onClick' in your component's class. You can bind the click event of the button element to the 'onClick' method using event binding as follows:
Click me
In this example, when the button is clicked, the 'onClick' method in the component's class will be called.
Follow-up 3
What is the use of two-way data binding?
Two-way data binding in Angular allows you to combine property binding and event binding into a single statement. It is denoted by square brackets and parentheses [()]. It is used to bind a property of a DOM element to a value in the component's class and also update the value in the component's class when the property changes.
For example, let's say you have an input element and a property called 'name' in your component's class. You can bind the value of the input element to the 'name' property using two-way data binding as follows:
In this example, the initial value of the input element will be set to the value of the 'name' property in the component's class. If the user changes the value of the input element, the 'name' property in the component's class will be updated automatically. Similarly, if the value of the 'name' property changes in the component's class, the value of the input element will also be updated automatically.
3. How is interpolation used in data binding?
Interpolation embeds a component's data into the template's text using double curly braces: Angular evaluates the expression inside {{ }} and renders the result as a string.
<h1>Hello, {{ user().name }}</h1>
<p>Total: {{ price * qty | currency }}</p>
It's one-way (class → view) and is really shorthand for property binding to the element's textContent. The expression can call methods and use pipes, but interviewers like you to know the constraints: template expressions must be side-effect-free and quick (they run on every change detection), and assignments, new, ++, ;, and most operators aren't allowed.
A modern performance note: prefer deriving displayed values with a computed() signal or a pure pipe rather than calling a method in interpolation — a method runs on every CD cycle, while a computed() recalculates only when its inputs change, which matters under both default and zoneless change detection.
Follow-up 1
Can you provide an example of interpolation?
Sure! Here's an example:
<p>Welcome, {{name}}!</p>
In this example, the value of the name property from the component's class will be dynamically inserted into the template.
Follow-up 2
What are the limitations of interpolation?
Interpolation has some limitations:
- It can only be used to display values, not to perform any logic or calculations.
- It can only be used to display simple values, such as strings, numbers, or booleans. It cannot be used to display complex objects or arrays.
- It does not support two-way data binding, meaning changes in the template will not be reflected back to the component's class.
Follow-up 3
How does interpolation differ from property binding?
Interpolation and property binding are both ways to pass data from a component's class to its template, but they have some differences:
- Interpolation is used to display values in the template, while property binding is used to set the value of an attribute or property of an HTML element.
- Interpolation uses the double curly braces {{}}, while property binding uses square brackets [] or parentheses ().
- Interpolation can only be used for one-way data binding, while property binding can be used for both one-way and two-way data binding.
4. What is the role of the ngModel directive in data binding?
ngModel provides two-way binding for form inputs in template-driven forms. With the banana-in-a-box syntax [(ngModel)]="prop", the input displays the property's value and writes user changes back to it automatically:
It's actually sugar for [ngModel]="name" (property in) plus (ngModelChange)="name = $event" (event out). To use it you must import FormsModule (in the component's imports for standalone).
Points interviewers probe: ngModel belongs to the template-driven approach — for complex, dynamic, or strongly-typed forms they expect reactive forms (FormControl/FormGroup) instead. And the current direction: Angular's new signal-based forms (stabilizing in v22) and the model() API offer signal-native two-way binding, so ngModel is increasingly reserved for simple template-driven cases.
Follow-up 1
Can you provide an example of how ngModel is used in two-way data binding?
Sure! Here's an example:
<p>Hello, {{ name }}!</p>
In this example, the value of the input element is bound to the name property in the component's model using the [(ngModel)] syntax. Any changes made to the input will automatically update the name property, and any changes made to the name property will be reflected in the input.
Follow-up 2
What happens if ngModel is not included in the FormsModule?
If the ngModel directive is not included in the FormsModule, Angular will throw an error when trying to use ngModel for two-way data binding. The FormsModule is responsible for providing the necessary infrastructure for ngModel to work, such as the NgModel directive and the FormsModule provider. Therefore, it is important to import the FormsModule in the module where ngModel is used.
Follow-up 3
How does ngModel relate to the FormsModule?
The ngModel directive is part of the FormsModule in Angular. The FormsModule is a module that provides support for template-driven forms, including features like two-way data binding with ngModel, form validation, and form submission handling. To use ngModel, the FormsModule must be imported in the module where ngModel is used.
5. How do you handle data binding in forms?
Angular gives you two approaches, and the right answer names both and when to use each:
- Template-driven forms — bind inputs with
[(ngModel)]and let directives (FormsModule) build the model implicitly from the template. Good for simple forms; less testable and harder to scale. - Reactive forms — define the model explicitly in the class with
FormControl/FormGroup/FormArray(viaReactiveFormsModule) and bind with[formGroup]/formControlName. Preferred for anything non-trivial: typed values, dynamic controls, synchronous access, and easy unit testing.
form = inject(FormBuilder).group({
email: ['', [Validators.required, Validators.email]],
});
The 2026 update worth mentioning: reactive forms are strictly typed (since v14), and Angular is rolling out signal-based forms (stabilizing in v22) that model form state as signals — the emerging modern option. For most current apps, reach for reactive forms as the default and template-driven only for the simplest cases.
Follow-up 1
What is the difference between template-driven and reactive forms in terms of data binding?
Template-driven forms use two-way data binding directly in the template. The form controls are created and managed by Angular based on the HTML template. Data binding is done using ngModel directive. On the other hand, reactive forms use a reactive approach to handle data binding. The form controls are created programmatically in the component using FormBuilder service. Data binding is done using form control objects and observables.
Follow-up 2
How can you validate user input using data binding?
In Angular, you can validate user input using data binding by applying validation rules to the form controls. Both template-driven and reactive forms support built-in and custom validators. Built-in validators include required, minLength, maxLength, pattern, and more. Custom validators can be created by defining a function that takes a form control as input and returns a validation error object if the input is invalid. You can then bind the validation error object to display error messages in the template.
Follow-up 3
Can you provide an example of data binding in a form?
Sure! Here's an example of data binding in a template-driven form:
Submit
In this example, the ngModel directive is used to bind the value of the input field to the user.name property in the component. The required attribute is used to specify that the input field is required. The #myForm template reference variable is used to reference the form in the component for form validation and submission.
And here's an example of data binding in a reactive form:
import { Component, OnInit } from '@angular/core';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
@Component({
selector: 'app-my-form',
templateUrl: './my-form.component.html',
styleUrls: ['./my-form.component.css']
})
export class MyFormComponent implements OnInit {
myForm: FormGroup;
constructor(private formBuilder: FormBuilder) { }
ngOnInit() {
this.myForm = this.formBuilder.group({
name: ['', Validators.required]
});
}
onSubmit() {
if (this.myForm.valid) {
// Form submission logic
}
}
}
In this example, the FormBuilder service is used to create a reactive form group with a single form control for the name field. The Validators.required validator is used to specify that the name field is required. The form group and form control are then bound to the template using the formGroup and formControlName directives.
Live mock interview
Mock interview: Data Binding
- Read your scene and goals
- Talk it out; goals tick off live
- Get a score and stronger lines
Your voice and your AI key never touch our servers; the key stays in this browser and is sent only to Google. Only your round scores are saved to track progress.