Given the component template below, what text will be shown in the browser?
<div>
<h1>{{ title }}</h1>
<p *ngIf="showDescription">Welcome to Angular!</p>
</div>Look at the *ngIf directive and the interpolation syntax.
The {{ title }} shows the string 'Hello Angular'. The *ngIf directive shows the paragraph only if showDescription is true. Since it is true, both heading and paragraph appear.
Choose the correct Angular template syntax to call onClick() when a button is clicked.
Angular uses parentheses for event binding.
The correct syntax for event binding uses parentheses around the event name, like (click). Square brackets are for property binding.
Given the component code below, what will the template render?
<ul>
<li *ngFor="let item of items; index as i">{{ i }}: {{ item }}</li>
</ul>Remember that index as i starts counting from zero.
The *ngFor directive loops over items. The index as i gives the zero-based index. So the list shows indices 0, 1, 2 with their items.
Examine the template code below. Why does Angular throw an error when rendering?
<div>
<p>{{ user.name }}</p>
</div>Think about what happens if user is not set yet.
If user is null or undefined, trying to access user.name causes a runtime error. Use safe navigation operator user?.name to avoid this.
Which statement best describes how Angular updates the view when a component's property changes?
Think about how Angular efficiently keeps the view in sync with data.
Angular's change detection checks component properties and updates only the parts of the DOM that need to change, making updates efficient.