0
0
Angularframework~5 mins

When to use OnPush in Angular - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the OnPush change detection strategy do in Angular?
OnPush tells Angular to check a component only when its input properties change or when an event happens inside it, improving performance by skipping unnecessary checks.
Click to reveal answer
beginner
When should you consider using OnPush in your Angular components?
Use OnPush when your component's inputs are immutable or rarely change, and you want to optimize performance by reducing how often Angular checks for changes.
Click to reveal answer
intermediate
How does OnPush affect Angular's change detection compared to the default strategy?
With OnPush, Angular skips checking the component unless input references change or an event occurs inside it, unlike the default strategy which checks every component every time.
Click to reveal answer
intermediate
What kind of data changes are detected by OnPush strategy?
OnPush detects changes when input properties receive new object references or primitive values change, but not when internal mutable data changes without new references.
Click to reveal answer
intermediate
Why is immutability important when using OnPush?
Because OnPush relies on detecting new references to inputs, using immutable data ensures Angular notices changes and updates the component correctly.
Click to reveal answer
What triggers Angular to check a component with OnPush strategy?
AWhen input properties change by reference or an event occurs inside the component
BEvery time any component changes in the app
COnly when the user clicks a button
DNever, OnPush disables change detection
Which scenario is best suited for OnPush strategy?
AComponent with immutable inputs that rarely change
BComponent with many internal mutable state changes
CComponent that updates every millisecond
DComponent with no inputs
What happens if you mutate an object input without changing its reference in an OnPush component?
AAngular will throw an error
BAngular will detect the change and update the view
CAngular will NOT detect the change and will NOT update the view
DAngular will reload the entire app
How can you manually trigger change detection in an OnPush component?
ABy adding more inputs
BBy refreshing the browser
CBy changing the component's selector
DBy injecting ChangeDetectorRef and calling markForCheck() or detectChanges()
What is a main benefit of using OnPush strategy?
ADisables Angular's change detection
BImproved performance by reducing unnecessary checks
CAutomatic detection of all changes
DSimpler code with no inputs
Explain when and why you would use the OnPush change detection strategy in Angular.
Think about how Angular decides to update components and how OnPush changes that.
You got /4 concepts.
    Describe how OnPush affects Angular's change detection compared to the default strategy.
    Compare the frequency and triggers of change detection in both strategies.
    You got /4 concepts.