Recall & Review
beginner
What is the purpose of the Angular component lifecycle?
It manages the different stages a component goes through from creation to destruction, allowing you to run code at specific moments.
Click to reveal answer
beginner
Name the lifecycle hook that runs once after the component's data-bound properties are initialized.
ngOnInit() runs once after input properties are set, perfect for initialization tasks.Click to reveal answer
beginner
Which lifecycle hook is called before Angular destroys a component?
ngOnDestroy() is called just before the component is removed, useful for cleanup like unsubscribing.Click to reveal answer
intermediate
What does the
ngOnChanges() hook do?It runs whenever input properties change, letting you react to those changes.
Click to reveal answer
intermediate
Why is
ngAfterViewInit() important?It runs after Angular fully initializes the component's view, so you can safely access child elements or components.
Click to reveal answer
Which lifecycle hook is called only once after component inputs are set?
✗ Incorrect
ngOnInit() runs once after inputs are initialized.When is
ngOnDestroy() called?✗ Incorrect
ngOnDestroy() runs just before the component is removed.What does
ngOnChanges() detect?✗ Incorrect
ngOnChanges() runs when input properties change.Which hook lets you access child components after the view is ready?
✗ Incorrect
ngAfterViewInit() runs after the component's view is fully initialized.Why use lifecycle hooks in Angular?
✗ Incorrect
Lifecycle hooks help manage component stages and run code at important times.
Explain the main Angular component lifecycle hooks and when they run.
Think about the component's journey from creation to destruction.
You got /4 concepts.
Describe a real-life scenario where you would use
ngOnDestroy() in an Angular component.Consider what happens when a component is no longer needed.
You got /4 concepts.