Control flow and deferrable views: Angular 22 practice questions
Control flow and deferrable views is 8% of the free Angular 22 mock (4 of 50 questions). Pick an answer to see right away whether it is correct, with the explanation and the documentation section it comes from.
NG.III · Angular 22 practice question
A developer is building a dashboard widget that contains a complex charting component. They want this chart to load instantly as soon as the rest of the dashboard renders, rather than waiting for user interaction or a delay. Which directive configuration should they use?
@defer (on immediate) {
<chart-component />
} @placeholder {
<div>Loading chart...</div>
}
Check answer and explanation
Correct answer: @defer (on immediate) { <chart-component /> } @placeholder { <div>Loading chart...</div> }
Explanation
The configuration '@defer (on immediate) { <chart-component /> }' instructs the framework to load the deferred content as soon as all other non-deferred content has finished rendering.
Common trap
Using 'on timer(0ms)' is functionally similar but is not the explicit trigger for immediate rendering, and using 'on hover' would only load it upon mouse interaction.
Source: Angular docs: Deferred loading with `@defer` — `on`
Checked against the cited text on 2026-11-25.
NG.III · Angular 22 practice question
A front-end engineer is implementing a dashboard widget that should only load its heavy data visualization component when the user is not actively interacting with other parts of the application. Which mechanism should they use to ensure the component is not rendered until the browser is idle?
@defer {
<HeavyVisualizationComponent />
}
Check answer and explanation
Correct answer: Wrap the component in a `@defer` block without any explicit trigger, relying on the default idle state.
Explanation
The appropriate method is to 'Wrap the component in a `@defer` block without any explicit trigger, relying on the default idle state.' This aligns with the source material, which indicates that a `@defer` block automatically activates when the browser enters an idle state.
Common trap
The suggestion to 'Use a `when: 'idle'` directive on the component tag to force lazy loading during idle periods' is flawed because the `@defer` syntax utilizes a `when:` attribute for specifying explicit conditions, rather than applying a directive directly to the element. Furthermore, 'Implement a custom `loadOnIdle` input property on the component itself' pertains to designing a component's interface, not utilizing the inherent lazy loading functionality.
Source: Angular docs: Deferred loading with `@defer` — `@defer`
Checked against the cited text on 2026-11-25.
NG.III · Angular 22 practice question
A frontend engineer is optimizing a dashboard page where a complex, rarely-used charting widget is present. To ensure the page loads quickly for the initial view, how should they implement the charting widget's loading mechanism?
@defer {
<complex-chart-widget />
}
Check answer and explanation
Correct answer: Wrap the widget in a `@defer` block to ensure its JavaScript bundle is fetched only after the initial page content is displayed.
Explanation
Wrapping the widget in a `@defer` block achieves the goal of deferring the loading of its code until it is actually needed, thereby improving initial load performance.
Common trap
Using the `async` pipe is for reactive data loading, not for controlling when the component's code is downloaded. `ngZone.runOutsideAngular()` is for performance optimization related to change detection, not bundle splitting.
Source: Angular docs: Deferred loading with `@defer` — Deferred loading with `@defer`
Checked against the cited text on 2026-11-25.
NG.III · Angular 22 practice question
A developer has a component, `LazyFeatureComponent`, which is not marked as standalone. They place this component inside an Angular `@defer` block in a parent template. What is the expected loading behavior for `LazyFeatureComponent`?
<div *ngIf="shouldLoad"><ng-container *defer="whenReady"><app-lazy-feature></app-lazy-feature></ng-container></div>
Check answer and explanation
Correct answer: The component will be eagerly loaded because it is not a standalone entity, regardless of its placement within the defer block.
Explanation
The component will be eagerly loaded because it is not a standalone entity, regardless of its placement within the defer block.
Common trap
The suggestion that 'the component will be deferred, but its transitive dependencies might still load upfront' is misleading because the primary dependency itself must satisfy the standalone requirement to be deferred.
Source: Angular docs: Deferred loading with `@defer` — Which dependencies are deferred?
Checked against the cited text on 2026-11-25.
NG.III · Angular 22 practice question
A developer is implementing a lazy-loaded widget using `@defer`. They want to display a loading spinner immediately while the widget data fetches. If they include an `@placeholder` block, what is the key characteristic regarding the placeholder's dependencies?
@defer {
<HeavyWidget />
} @placeholder {
<Spinner />
}
Check answer and explanation
Correct answer: The dependencies required by the placeholder block are loaded immediately when the component initializes, regardless of when the `@defer` block triggers.
Explanation
The accurate description is that 'The dependencies required by the placeholder block are loaded immediately when the component initializes, regardless of when the `@defer` block triggers,' because the documentation specifies that 'dependencies of the placeholder block are eagerly loaded.'
Common trap
The description stating 'The placeholder content is only rendered after the main widget successfully loads, providing a visual cue during the fetch' describes a behavior more akin to standard lazy loading without a placeholder, and the statement 'The placeholder content is rendered asynchronously, meaning its loading time is dependent on the widget's network latency' incorrectly implies the placeholder's rendering is governed by the main content's network timing.
Source: Angular docs: Deferred loading with `@defer` — Show placeholder content with `@placeholder`
Checked against the cited text on 2026-11-25.
NG.III · Angular 22 practice question
A developer implements a component that loads a heavy widget only when a user's subscription status becomes 'premium'. This widget is wrapped in an `@defer` block using a `when` trigger. If the user later downgrades their account, what will happen to the loaded widget?
<div *ngIf="isPremium()">
@defer (when "isPremium()") {
<heavyWidget />
} @placeholder {
Loading...
}
</div>
Check answer and explanation
Correct answer: The widget will remain visible, as the initial successful loading state is permanent once the 'when' condition is met.
Explanation
The widget will remain visible because the initial successful loading state is permanent once the 'when' condition is met.
Common trap
Suggesting that the widget will automatically unload and revert to the 'Loading...' placeholder because the condition is now false contradicts the one-time nature of the trigger. Stating that the widget will only load if the condition is true at the moment the view is initialized, regardless of subsequent state changes, is too vague and does not capture the specific behavior of the trigger.
Source: Angular docs: Deferred loading with `@defer` — `when`
Checked against the cited text on 2026-11-25.
NG.III · Angular 22 practice question
A developer needs to load a heavy component only when the user clicks on a specific element within the template, and this element is not the placeholder itself. How should they configure the `@defer` block?
<div #triggerElement>Click Me</div>
@defer (on interaction(triggerElement)) {
<HeavyComponent />
} @placeholder {
<div>Loading...</div>
}
Check answer and explanation
Correct answer: @defer (on interaction(triggerElement)) { <HeavyComponent /> } @placeholder { ... }
Explanation
The appropriate setup mandates using `on interaction(triggerElement)` to ensure the component loads when the element designated by the template variable `triggerElement` is interacted with.
Common trap
The configuration that utilizes the default placeholder interaction will disregard the specific element, while the setup employing `click` as the trigger keyword is incorrect for handling general interaction events.
Source: Angular docs: Deferred loading with `@defer` — `on`
Checked against the cited text on 2026-11-25.
NG.III · Angular 22 practice question
A developer is rendering a list of user profiles using the new `@for` block. When the list items are reordered but the underlying objects themselves are not replaced, what is the primary benefit of supplying a unique `track` expression?
@for (user of users; track user.id) {
<div>{{ user.name }}</div>
}
Check answer and explanation
Correct answer: Angular will reuse the existing DOM elements for the profiles, only updating the necessary data bindings instead of rebuilding the entire list structure.
Explanation
The correct approach is to allow Angular to reuse the existing DOM elements for the profiles, modifying only the necessary data bindings rather than rebuilding the entire list structure. This is because when a tracked property changes while the object reference remains constant, Angular updates the view's bindings instead of destroying and recreating the entire element.
Common trap
The suggestion that the application will automatically use the element's index if a unique ID is not explicitly provided is flawed because using the index is only appropriate for collections that do not change their order, and the assertion that the rendering process will always destroy and recreate the DOM nodes because object references change during reordering is incorrect, as reference identity comparison is discouraged due to performance issues.
Source: Angular docs: Control flow — Why is `track` in `@for` blocks important?
Checked against the cited text on 2026-11-25.
NG.III · Angular 22 practice question
A developer is writing an integration test for a component utilizing an `@defer` block. To ensure they can programmatically force the defer block through its lifecycle stages (e.g., from placeholder to loading to complete) within the test environment, what configuration must they apply to the testing module?
@defer {
<HeavyWidget />
} @placeholder {
Loading...
} @loading {
Fallback
}
Check answer and explanation
Correct answer: Set `TestBed.configureTestingModule({ deferBlockBehavior: DeferBlockBehavior.Manual });`
Explanation
The official documentation indicates that configuring the testing module with `deferBlockBehavior: DeferBlockBehavior.Manual` enables granular control over the defer block states during testing procedures.
Common trap
Attempting to configure the testing module using `deferBlockBehavior: DeferBlockBehavior.Forced` will fail because that enum value does not exist, and invoking `componentFixture.triggerDeferBlock(DeferBlockState.Manual)` describes an incorrect method for managing the block's state.
Source: Angular docs: Deferred loading with `@defer` — Testing `@defer` blocks
Checked against the cited text on 2026-11-25.