Angular · Junior · Question 34 of 75
What is ngOnInit typically used for?
- ✓Correct answer: Initialization that needs the component's inputs, such as loading data
- 2Cleaning up subscriptions
- 3Defining the component's template
Explanation
Inputs are already set when ngOnInit runs, but not yet in the constructor. The constructor is for injecting dependencies; heavier work belongs in ngOnInit.