NG.I · Angular 22 practice question
A developer is implementing a custom lifecycle hook within a component. Based on the documentation, what is the fundamental constraint regarding state modifications during the component traversal phase?
import { Component } from '@angular/core';
@Component({
selector: 'app-data-handler',
standalone: true,
template: '<div>Loading...</div>'
})
export class DataHandlerComponent {
ngOnInit() {
// Logic here
}
}
Check answer and explanation
Correct answer: They should always avoid modifying component state during the traversal, as this can interfere with Angular's update checks.
Explanation
The appropriate guideline is to refrain from altering component state while iterating through the structure, because such modifications risk disrupting Angular's update verification process. This aligns with the documentation's statement that the traversal visits each component only one time.
Common trap
The suggestion that operations must be exclusively synchronous is inaccurate, as the documentation does not impose such a limitation. Furthermore, the advice permitting state changes, contingent upon batching and occurring after the component's initialization hook, contradicts the source's explicit caution against subsequent state modifications during the traversal.
Source: Angular docs: Component Lifecycle — Component Lifecycle
Checked against the cited text on 2026-11-25.