0
0
Angularframework~5 mins

Why lifecycle hooks matter in Angular - Quick Recap

Choose your learning style9 modes available
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?
AngDoCheck
BngOnDestroy
CngAfterViewInit
DngOnInit
What is the main use of ngOnDestroy?
AStart fetching data
BClean up resources before component removal
CDetect changes in data
DRender the component view
Why should you use lifecycle hooks in Angular?
ATo write CSS
BTo style components
CTo manage component setup and cleanup
DTo create new components
Which hook runs after Angular has fully initialized a component's view?
AngAfterViewInit
BngOnInit
CngOnDestroy
DngOnChanges
What can happen if you ignore ngOnDestroy when using subscriptions?
AMemory leaks occur
BComponent styles break
CApp runs faster
DComponent never renders
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.