0
0
Angularframework~5 mins

ngOnChanges for input changes in Angular - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the purpose of the ngOnChanges lifecycle hook in Angular?
It runs when Angular sets or resets data-bound input properties. It helps detect and respond to changes in input values.
Click to reveal answer
beginner
How does Angular provide information about input changes inside ngOnChanges?
Angular passes a SimpleChanges object that contains previous and current values for each changed input property.
Click to reveal answer
beginner
True or False: ngOnChanges is called only once during the component's lifecycle.
False. ngOnChanges is called every time an input property changes, including the first time the input is set.
Click to reveal answer
intermediate
What must a component do to use ngOnChanges?
It must implement the OnChanges interface and define the ngOnChanges(changes: SimpleChanges) method.
Click to reveal answer
beginner
What is a common use case for ngOnChanges?
To react to changes in input properties, such as updating internal state or triggering side effects when inputs change.
Click to reveal answer
When is ngOnChanges called in an Angular component?
AOnly when the component is destroyed
BWhenever an input property changes
COnly once when the component is created
DWhen a button is clicked
What argument does ngOnChanges receive?
AThe component's selector
BThe component's template
CAn object with previous and current input values
DNo arguments
Which interface must a component implement to use ngOnChanges?
AOnChanges
BOnInit
CDoCheck
DAfterViewInit
Can ngOnChanges detect changes in properties that are not inputs?
AOnly for output properties
BYes, all properties trigger it
COnly if manually called
DNo, only input properties trigger <code>ngOnChanges</code>
What can you do inside ngOnChanges?
AUpdate internal state based on new input values
BChange the component's selector
CModify the component's template HTML
DDestroy the component
Explain how ngOnChanges works and when it is triggered in an Angular component.
Think about how Angular tracks changes to inputs.
You got /3 concepts.
    Describe a practical scenario where you would use ngOnChanges in your Angular component.
    Consider when input data affects component behavior.
    You got /3 concepts.