Bird
0
0

What is wrong with this component code?

medium📝 Debug Q6 of 15
Angular - Change Detection
What is wrong with this component code?
@Component({ selector: 'app', template: '{{counter}}', changeDetection: ChangeDetectionStrategy.Default }) export class AppComponent { counter = 0; increment() { this.counter += 1 } }

The view does not update after calling increment().
AMissing parentheses after increment method call
BNo error, default strategy updates view automatically
CCounter property is not declared as @Input
DChangeDetectionStrategy.Default is not imported
Step-by-Step Solution
Solution:
  1. Step 1: Check for import errors

    If ChangeDetectionStrategy.Default is used but not imported from '@angular/core', Angular will not recognize it, causing no update.
  2. Step 2: Verify other possible issues

    Increment method syntax is correct, default strategy updates automatically, and @Input is not required for internal properties.
  3. Final Answer:

    ChangeDetectionStrategy.Default is not imported -> Option D
  4. Quick Check:

    Missing import of ChangeDetectionStrategy causes no update [OK]
Quick Trick: Always import ChangeDetectionStrategy from '@angular/core' [OK]
Common Mistakes:
MISTAKES
  • Forgetting to import ChangeDetectionStrategy
  • Assuming @Input needed for all properties
  • Missing method call parentheses

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes