Bird
0
0

Which syntax correctly sets the change detection strategy to OnPush in an Angular component?

easy📝 Syntax Q12 of 15
Angular - Change Detection
Which syntax correctly sets the change detection strategy to OnPush in an Angular component?
A@Component({ detectionStrategy: OnPush })
B@Component({ changeDetection: ChangeDetectionStrategy.Default })
C@Component({ changeDetection: ChangeDetectionStrategy.OnPush })
D@Component({ changeDetectionStrategy: 'OnPush' })
Step-by-Step Solution
Solution:
  1. Step 1: Recall correct property name

    The property to set change detection is 'changeDetection' inside @Component decorator.
  2. Step 2: Use correct enum value

    The enum value for OnPush is ChangeDetectionStrategy.OnPush, not a string or other property name.
  3. Final Answer:

    @Component({ changeDetection: ChangeDetectionStrategy.OnPush }) -> Option C
  4. Quick Check:

    Use changeDetection with ChangeDetectionStrategy.OnPush [OK]
Quick Trick: Use changeDetection: ChangeDetectionStrategy.OnPush exactly [OK]
Common Mistakes:
MISTAKES
  • Using wrong property name like detectionStrategy
  • Passing 'OnPush' as string
  • Confusing Default with OnPush

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes