NG.I · Angular 22 practice question

A developer is applying both a custom structural directive and a component to the same host element in an Angular template. They rely on the component's `ngOnInit` running strictly before the directive's `ngOnInit`. What is the safest architectural assumption to make regarding this execution order?

<div app-my-component app-my-directive></div>
Choose one answer
Check answer and explanation

Correct answer: The framework offers no guaranteed ordering between the component's and the directive's lifecycle hooks when applied to the same host element.

Explanation

The accurate statement is that the framework offers no guaranteed ordering between the component's and the directive's lifecycle hooks when applied to the same host element, as the official documentation explicitly states that no ordering is guaranteed.

Common trap

The assertion that the execution order is strictly guaranteed by the Angular framework to be component initialization followed by directive initialization implies a strict, predictable dependency, which is what the documentation warns against. Similarly, the suggestion that the framework provides a predictable sequence for when the component and associated directives execute their lifecycle hooks on the same element is also false.

Source: Angular docs: Component Lifecycle — Ordering with directives
Checked against the cited text on 2026-11-25.

Report an error in this question