Bird
0
0

Consider this Angular component snippet:

medium📝 Conceptual Q5 of 15
Angular - Lifecycle Hooks
Consider this Angular component snippet:
export class TestComponent implements DoCheck {
  ngDoCheck() { console.log('Change detection running'); }
}

How often will 'Change detection running' be logged during the component lifecycle?
AEvery time Angular runs change detection
BOnly once after initialization
COnly when input properties change
DOnly when the component is destroyed
Step-by-Step Solution
Solution:
  1. Step 1: Understand ngDoCheck purpose

    ngDoCheck runs every time Angular runs change detection to detect and act on changes.
  2. Step 2: Confirm frequency of ngDoCheck calls

    It is called frequently, not just once or on input change, but on every change detection cycle.
  3. Final Answer:

    Every time Angular runs change detection -> Option A
  4. Quick Check:

    ngDoCheck runs on every change detection [OK]
Quick Trick: ngDoCheck runs on every change detection cycle [OK]
Common Mistakes:
  • Thinking it runs only once
  • Confusing with ngOnChanges
  • Assuming it runs on destroy

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes