0
0
Angularframework~20 mins

When to use OnPush in Angular - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
OnPush Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
How does OnPush change Angular component behavior?
Consider an Angular component with ChangeDetectionStrategy.OnPush. What triggers this component to check for updates and re-render?
AIt updates on every change detection cycle regardless of inputs or events.
BIt updates only when manually triggered by calling <code>detectChanges()</code>.
CIt updates only when a global timer triggers change detection.
DIt updates only when its input properties change or an event inside the component occurs.
Attempts:
2 left
💡 Hint
Think about what Angular watches to decide if a component needs to update when using OnPush.
🧠 Conceptual
intermediate
2:00remaining
Why choose OnPush for a component?
What is the main benefit of using ChangeDetectionStrategy.OnPush in Angular components?
AIt disables change detection completely for the component.
BIt reduces unnecessary checks, improving performance especially in large apps.
CIt allows the component to update automatically on any data change anywhere in the app.
DIt forces the component to update every second regardless of changes.
Attempts:
2 left
💡 Hint
Think about how OnPush affects how often Angular checks the component.
state_output
advanced
2:00remaining
What happens if an OnPush component's input object is mutated?
Given an OnPush component receiving an object as input, what happens if the object’s properties change but the object reference stays the same?
AThe component will NOT detect changes and will NOT update its view.
BThe component will detect changes and update immediately.
CAngular throws an error because mutation is not allowed.
DThe component updates only if a manual change detection is triggered.
Attempts:
2 left
💡 Hint
OnPush relies on object references, not deep property changes.
🔧 Debug
advanced
2:00remaining
Why does an OnPush component not update after input changes?
An OnPush component receives a new input object but its view does not update. What is the most likely cause?
AThe input object reference did not actually change; only its properties were mutated.
BThe component is missing the <code>@Input()</code> decorator on the input property.
CThe component is using the default change detection strategy instead of OnPush.
DAngular does not support OnPush with object inputs.
Attempts:
2 left
💡 Hint
Check if the input object reference changes when updating inputs.
📝 Syntax
expert
2:00remaining
Correct syntax to enable OnPush change detection
Which of the following is the correct way to set ChangeDetectionStrategy.OnPush in an Angular component?
A@Component({ selector: 'app', templateUrl: './app.html', changeDetectionStrategy: ChangeDetectionStrategy.OnPush })
B@Component({ selector: 'app', templateUrl: './app.html', changeDetection: 'OnPush' })
C@Component({ selector: 'app', templateUrl: './app.html', changeDetection: ChangeDetectionStrategy.OnPush })
D@Component({ selector: 'app', templateUrl: './app.html', changeDetection: OnPush })
Attempts:
2 left
💡 Hint
Check the exact property name and value type for setting change detection strategy.