name bound to an input field using two-way binding. What is the result when the user types a new name in the input?import { Component } from '@angular/core'; @Component({ selector: 'app-name-input', standalone: true, template: ` <input [(ngModel)]="name" aria-label="Name input" /> <p>Hello, {{ name }}!</p> ` }) export class NameInputComponent { name = 'Alice'; }
Two-way binding with [(ngModel)] keeps the component property and input value in sync. When the user types, the property updates immediately, and Angular updates the displayed greeting.
count() after the user clicks the button twice?import { Component, signal } from '@angular/core'; @Component({ selector: 'app-counter', standalone: true, template: ` <button (click)="increment()" aria-label="Increment button">Increment</button> <p>Count: {{ count() }}</p> ` }) export class CounterComponent { count = signal(0); increment() { this.count.set(this.count() + 1); } }
The increment method adds 1 to the current count signal value each time the button is clicked. After two clicks, the count is 2.
title to an input element so that changes update the property immediately. Which code snippet is correct?Option D uses Angular's two-way binding syntax [(ngModel)], which binds the input value to the component property and updates it on user input.
Option D is a manual way but less idiomatic and requires extra code.
Options C and D are invalid syntax or one-way binding only.
message property changes after 2 seconds, but the displayed text does not update. Why?import { Component, NgZone } from '@angular/core'; @Component({ selector: 'app-message', standalone: true, template: `<p>{{ message }}</p>` }) export class MessageComponent { message = 'Hello'; constructor(private ngZone: NgZone) { this.ngZone.runOutsideAngular(() => { setTimeout(() => { this.message = 'Goodbye'; }, 2000); }); } }
Without signals or manual change detection, Angular may not detect changes made asynchronously outside Angular's zone. Using signals or triggering change detection fixes this.
Data binding in Angular connects the component data and the UI automatically. This reduces manual work, keeps the UI updated, and helps avoid bugs from out-of-sync data.