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?✗ Incorrect
ngOnChanges runs every time Angular updates an input property.What argument does
ngOnChanges receive?✗ Incorrect
ngOnChanges receives a SimpleChanges object with details about input changes.Which interface must a component implement to use
ngOnChanges?✗ Incorrect
Implementing
OnChanges interface allows defining the ngOnChanges method.Can
ngOnChanges detect changes in properties that are not inputs?✗ Incorrect
ngOnChanges only runs for changes in input properties decorated with @Input().What can you do inside
ngOnChanges?✗ Incorrect
ngOnChanges is used to respond to input changes, often updating internal data.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.