In Angular, a container component is responsible for managing data and logic, while a presentational component focuses on displaying UI. Given the following scenario, which behavior best describes a container component?
import { Component, signal } from '@angular/core'; @Component({ selector: 'app-user-container', standalone: true, template: `<app-user-profile [user]="user()"></app-user-profile>`, imports: [UserProfileComponent] }) export class UserContainerComponent { user = signal({ name: 'Alice', age: 30 }); }
Think about which component holds the data and which one just shows it.
The container component manages the data and passes it as inputs to presentational components, which focus on UI rendering.
Given a presentational component that receives a user object as input and displays the user's name, what will be rendered?
import { Component, Input } from '@angular/core'; @Component({ selector: 'app-user-profile', standalone: true, template: `<p>User: {{ user.name }}</p>` }) export class UserProfileComponent { @Input() user!: { name: string; age: number }; } // Usage in container template: // <app-user-profile [user]="{ name: 'Bob', age: 25 }"></app-user-profile>
Look at how the template accesses the user property.
The template uses interpolation to show the user's name property, so it will display 'User: Bob'.
In Angular standalone components using signals, when does the presentational component update its display after the container component changes the data?
import { Component, signal } from '@angular/core'; @Component({ selector: 'app-container', standalone: true, template: `<app-display [data]="data()"></app-display>`, imports: [DisplayComponent] }) export class ContainerComponent { data = signal('initial'); updateData() { this.data.set('updated'); } }
Signals automatically notify Angular when their value changes.
Signals in Angular trigger automatic updates to any bindings that depend on them, so the presentational component updates immediately.
Choose the correct Angular standalone presentational component that accepts an input and displays it.
Check the syntax for declaring inputs and standalone components.
Option A correctly uses @Input() decorator with parentheses and marks the component as standalone.
Given this container and presentational component setup, why does the UI not update when the container changes the data?
import { Component, signal, Input } from '@angular/core'; @Component({ selector: 'app-container', standalone: true, template: `<app-display [data]="data"></app-display>`, imports: [DisplayComponent] }) export class ContainerComponent { data = signal('hello'); changeData() { this.data.set('world'); } } @Component({ selector: 'app-display', standalone: true, template: `<p>{{ data }}</p>` }) export class DisplayComponent { @Input() data!: string; }
Check what is passed as input and what the presentational component expects.
The container passes the signal object instead of its current value, so the presentational component receives a signal object, not a string, and does not update when the signal changes.