Recall & Review
beginner
What are lifecycle hooks in Angular?
Lifecycle hooks are special methods in Angular components that let you tap into key moments of a component's life, like when it is created, updated, or destroyed.Click to reveal answer
beginner
Why is ngOnInit important?
ngOnInit runs once after the component is created. It is used to initialize data or start processes like fetching data from a server.
Click to reveal answer
intermediate
How do lifecycle hooks help with resource management?
Hooks like ngOnDestroy let you clean up resources such as timers or subscriptions to avoid memory leaks when a component is removed.Click to reveal answer
intermediate
What happens if you don’t use lifecycle hooks properly?
Without proper use of lifecycle hooks, your app might fetch data too late, leak memory, or behave unpredictably because components miss key setup or cleanup steps.
Click to reveal answer
beginner
Name two lifecycle hooks and their main purpose.
ngOnInit: Initialize component data.<br>ngOnDestroy: Clean up before component is removed.
Click to reveal answer
Which lifecycle hook is called once after component creation?
✗ Incorrect
ngOnInit runs once after the component is created to initialize data.
What is the main use of ngOnDestroy?
✗ Incorrect
ngOnDestroy is used to clean up timers, subscriptions, or other resources to prevent memory leaks.
Why should you use lifecycle hooks in Angular?
✗ Incorrect
Lifecycle hooks help manage important moments like setup and cleanup in a component's life.
Which hook runs after Angular has fully initialized a component's view?
✗ Incorrect
ngAfterViewInit runs after the component's view and child views are initialized.
What can happen if you ignore ngOnDestroy when using subscriptions?
✗ Incorrect
Ignoring ngOnDestroy can cause memory leaks because subscriptions stay active after component removal.
Explain why lifecycle hooks are important in Angular components.
Think about what happens when a component starts and ends.
You got /5 concepts.
Describe the roles of ngOnInit and ngOnDestroy hooks.
One runs at start, the other at end.
You got /3 concepts.