0
0
Angularframework~5 mins

Component lifecycle overview in Angular - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
AngAfterViewInit()
BngOnDestroy()
CngOnChanges()
DngOnInit()
When is ngOnDestroy() called?
ABefore component removal
BAfter component view initialization
CBefore component creation
DWhen input properties change
What does ngOnChanges() detect?
AComponent destruction
BChanges in input properties
CView initialization
DComponent creation
Which hook lets you access child components after the view is ready?
AngAfterViewInit()
BngOnChanges()
CngOnDestroy()
DngOnInit()
Why use lifecycle hooks in Angular?
ATo style components
BTo write HTML templates
CTo manage component stages and run code at key moments
DTo create new components
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.