NG.II · Angular 22 practice question

A developer is integrating a complex third-party charting library into an Angular component. This library requires direct access to the rendered DOM element to initialize and update its visualization after Angular has applied its structural changes. Which Angular signal API should the developer use to ensure the chart updates correctly after the view has been committed?

afterRenderEffect(() => {
  // Logic to call chart.updateData(data) using the DOM element
});
Choose one answer
Check answer and explanation

Correct answer: afterRenderEffect(() => { /* DOM manipulation logic */ });

Explanation

The developer must use 'afterRenderEffect' because it guarantees the code runs after Angular has finished committing changes to the DOM, which is necessary for interacting with external libraries that need a fully rendered view.

Common trap

Using 'effect' would execute before Angular updates the DOM, meaning the DOM element might not yet be available or stable for the third-party library. While 'MutationObserver' can watch for changes, it is not the correct mechanism for reacting to a specific rendering lifecycle event.

Source: Angular docs: Effects — Side effects on DOM elements
Checked against the cited text on 2026-11-25.

Report an error in this question