Recall & Review
beginner
What is the OnPush change detection strategy in Angular?
OnPush is a change detection strategy that tells Angular to check a component only when its input properties change or when an event happens inside it. This helps improve performance by reducing unnecessary checks.
Click to reveal answer
intermediate
How does Angular detect changes with OnPush strategy?
Angular runs change detection for an OnPush component only when:<br>1. An input property changes by reference.<br>2. An event originated from the component or its children.<br>3. An observable or async pipe inside the component emits a new value.
Click to reveal answer
intermediate
What happens if you mutate an object input without changing its reference in an OnPush component?
Angular will NOT detect the change because OnPush checks only for new object references. Mutating the object without changing its reference means Angular thinks nothing changed.
Click to reveal answer
advanced
How can you trigger change detection manually in an OnPush component?
You can inject ChangeDetectorRef and call its markForCheck() or detectChanges() methods to tell Angular to check the component for updates.
Click to reveal answer
beginner
Why is OnPush strategy good for performance?
OnPush reduces how often Angular checks components by only running change detection when needed. This lowers CPU work and speeds up apps, especially with many components.
Click to reveal answer
When does Angular run change detection for an OnPush component?
✗ Incorrect
OnPush runs change detection only when input references change or events inside the component occur.
What happens if you mutate an input object without changing its reference in an OnPush component?
✗ Incorrect
OnPush checks input references, so mutating without changing reference is ignored.
Which Angular service can you use to manually trigger change detection in an OnPush component?
✗ Incorrect
ChangeDetectorRef lets you manually trigger change detection.
What is a main benefit of using OnPush strategy?
✗ Incorrect
OnPush improves performance by reducing unnecessary change detection.
Which of these will NOT trigger change detection in an OnPush component?
✗ Incorrect
Mutating an input object without changing its reference does not trigger change detection with OnPush.
Explain how the OnPush change detection strategy works in Angular and why it improves performance.
Think about when Angular decides to update the component view.
You got /4 concepts.
Describe how you can handle a situation where an OnPush component does not update after mutating an input object.
Consider how Angular detects changes with OnPush.
You got /4 concepts.