0
0
Angularframework~20 mins

Performance impact of change detection in Angular - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Angular Change Detection Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
How does Angular's default change detection strategy affect component updates?

Consider an Angular component using the default change detection strategy. What happens when a parent component updates a property that a child component uses?

Angular
ParentComponent template:
<child-component [data]="parentData"></child-component>

ChildComponent:
@Input() data: string;

// Default change detection strategy

// Parent updates parentData on button click
AThe child component never updates unless manually triggered by the developer.
BThe child component always runs change detection and updates its view whenever the parent changes, even if the input value is the same.
CThe child component updates only if the parent component calls detectChanges() explicitly.
DThe child component only updates if the input value changes by reference, ignoring primitive value changes.
Attempts:
2 left
💡 Hint

Think about how Angular's default change detection checks all components on every event.

state_output
intermediate
2:00remaining
What is the effect of using OnPush change detection strategy on a component's update behavior?

Given a component with ChangeDetectionStrategy.OnPush, which of the following triggers the component to update?

Angular
Component decorator:
@Component({
  selector: 'my-comp',
  changeDetection: ChangeDetectionStrategy.OnPush
})
export class MyComp {
  @Input() data: string;
}
AThe component updates only when its input reference changes or an event inside the component occurs.
BThe component updates only when detectChanges() is called manually.
CThe component updates on every change detection cycle regardless of input changes.
DThe component never updates after initial rendering.
Attempts:
2 left
💡 Hint

OnPush optimizes by checking inputs by reference and internal events.

📝 Syntax
advanced
2:00remaining
Identify the correct way to detach change detection manually in Angular

Which code snippet correctly detaches change detection for a component using ChangeDetectorRef?

Aconstructor(private cd: ChangeDetectorRef) { this.cd.pause(); }
Bconstructor(private cd: ChangeDetectorRef) { this.cd.stop(); }
Cconstructor(private cd: ChangeDetectorRef) { this.cd.detach(); }
Dconstructor(private cd: ChangeDetectorRef) { this.cd.disable(); }
Attempts:
2 left
💡 Hint

Look for the official method name to stop change detection.

🔧 Debug
advanced
2:00remaining
Why does a component with OnPush not update when a nested object property changes?

Given a component with ChangeDetectionStrategy.OnPush and an input object, why does updating a nested property not update the view?

Angular
Parent template:
<child-comp [data]="parentData"></child-comp>

Parent component:
parentData = { name: 'Alice', age: 30 };

// Later update
this.parentData.age = 31;
ABecause the parent component must use ChangeDetectorRef.markForCheck() after mutation.
BBecause Angular does not detect any changes inside objects regardless of strategy.
CBecause the child component must call detectChanges() manually after mutation.
DBecause OnPush only checks for input reference changes, mutating a nested property does not change the object reference.
Attempts:
2 left
💡 Hint

Think about how OnPush compares input values.

🧠 Conceptual
expert
3:00remaining
What is the main performance benefit of using OnPush change detection in Angular?

Why does using ChangeDetectionStrategy.OnPush improve performance in large Angular applications?

AIt reduces the number of components Angular checks by only running change detection when input references change or events occur inside the component.
BIt disables change detection entirely, so Angular never updates the component after initial render.
CIt forces Angular to check components more frequently to catch changes faster.
DIt caches component views to avoid re-rendering even when inputs change.
Attempts:
2 left
💡 Hint

Consider how Angular decides when to check components with OnPush.