Recall & Review
beginner
What is the purpose of manually triggering change detection in Angular?
Manually triggering change detection lets you tell Angular to check for updates in the UI when Angular's automatic detection doesn't catch changes, like when changes happen outside Angular's zone.
Click to reveal answer
beginner
Which Angular service is commonly used to trigger change detection manually?
The
ChangeDetectorRef service is used to manually trigger change detection by calling its detectChanges() method.Click to reveal answer
intermediate
How do you use
ChangeDetectorRef to trigger change detection in a component?Inject
ChangeDetectorRef in the component constructor, then call this.cdRef.detectChanges() when you want Angular to update the view manually.Click to reveal answer
intermediate
What is the difference between
detectChanges() and markForCheck() in Angular's change detection?detectChanges() immediately runs change detection on the component and its children. markForCheck() marks the component to be checked in the next change detection cycle, useful with OnPush strategy.Click to reveal answer
intermediate
Why might Angular's automatic change detection miss some updates, requiring manual triggering?
Angular's automatic detection misses updates when changes happen outside Angular's zone, like in setTimeout, third-party libraries, or direct DOM events, so manual triggering is needed to update the UI.
Click to reveal answer
Which method on ChangeDetectorRef triggers immediate change detection?
✗ Incorrect
detectChanges() runs change detection immediately on the component and its children.When should you manually trigger change detection in Angular?
✗ Incorrect
Manual triggering is needed when changes happen outside Angular's zone, like in setTimeout or third-party code.
What does
markForCheck() do in Angular's change detection?✗ Incorrect
markForCheck() marks the component to be checked in the next change detection cycle.How do you inject ChangeDetectorRef in an Angular component?
✗ Incorrect
You import ChangeDetectorRef from '@angular/core' and inject it via the component constructor.
Which Angular change detection strategy benefits most from manual triggering?
✗ Incorrect
OnPush strategy requires manual triggers like markForCheck() or detectChanges() to update views on external changes.
Explain why and how you would manually trigger change detection in an Angular component.
Think about asynchronous code or third-party libraries.
You got /4 concepts.
Describe the difference between detectChanges() and markForCheck() methods in Angular's ChangeDetectorRef.
One is immediate, the other is deferred.
You got /4 concepts.