Bird
0
0

Consider this Angular component:

medium📝 Debug Q7 of 15
Angular - Change Detection
Consider this Angular component:
@Component({ selector: 'app-value', changeDetection: ChangeDetectionStrategy.OnPush }) export class ValueComponent { @Input() number = 0; increment() { this.number++; } }

Why might the template not reflect the incremented value?
ABecause OnPush disables all change detection
BBecause the input 'number' is mutated directly without changing its reference
CBecause @Input() properties cannot be changed inside the component
DBecause the increment method is not called in the template
Step-by-Step Solution
Solution:
  1. Step 1: OnPush and Inputs

    OnPush triggers detection when input references change.
  2. Step 2: Analyze Mutation

    Incrementing a primitive input directly does not change its reference.
  3. Step 3: Result

    Angular does not detect the change, so the view is not updated.
  4. Final Answer:

    Because the input 'number' is mutated directly without changing its reference -> Option B
  5. Quick Check:

    OnPush requires new input references to update [OK]
Quick Trick: OnPush needs new input references to detect changes [OK]
Common Mistakes:
MISTAKES
  • Believing OnPush disables all detection
  • Thinking inputs cannot be changed internally
  • Assuming method call alone triggers update

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes