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.