Sometimes Angular does not detect changes automatically, so manual trigger is needed.
Final Answer:
Change detection was not triggered after changing the value. -> Option B
Quick Check:
Missing change detection = no UI update [OK]
Hint: Always trigger change detection after manual data changes [OK]
Common Mistakes:
Blaming variable declaration
Thinking selector is wrong
Assuming templates can't show variables
5. You have a list of user objects and want to display their names in Angular. You update the list by replacing it with a new array but the UI does not refresh. What is the best way to ensure Angular detects the change?
hard
A. Restart the Angular application.
B. Modify the existing array without replacing it.
C. Use setTimeout to delay the update.
D. Manually call changeDetectorRef.detectChanges() after updating the list.
Solution
Step 1: Understand Angular's change detection on object references
Angular detects changes when object references change or manual detection runs.
Step 2: Analyze options for updating the list
Replacing the array changes reference but sometimes Angular needs manual detectChanges() call to update UI immediately.
Step 3: Evaluate other options
Modifying existing array may not trigger detection; setTimeout delays but is unreliable; restarting app is extreme.
Final Answer:
Manually call changeDetectorRef.detectChanges() after updating the list. -> Option D
Quick Check:
Manual detectChanges() ensures UI updates [OK]
Hint: Call detectChanges() after replacing data arrays [OK]
Common Mistakes:
Modifying array without changing reference
Using setTimeout as a fix
Restarting app instead of fixing detection
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.