Bird
0
0

How do you specify the OnPush change detection strategy in an Angular component?

easy📝 Syntax Q3 of 15
Angular - Change Detection
How do you specify the OnPush change detection strategy in an Angular component?
AAdd <code>changeDetection: ChangeDetectionStrategy.OnPush</code> in the @Component decorator
BSet <code>changeDetection: 'OnPush'</code> in the component class constructor
CUse <code>@ChangeDetection('OnPush')</code> decorator on the component class
DCall <code>this.changeDetectorRef.setStrategy('OnPush')</code> inside ngOnInit
Step-by-Step Solution
Solution:
  1. Step 1: Recall Angular syntax

    The change detection strategy is set in the component metadata, inside the @Component decorator.
  2. Step 2: Correct syntax

    Use changeDetection: ChangeDetectionStrategy.OnPush as a property in the decorator.
  3. Final Answer:

    Add changeDetection: ChangeDetectionStrategy.OnPush in the @Component decorator -> Option A
  4. Quick Check:

    Change detection strategy is a decorator property [OK]
Quick Trick: Set changeDetection in @Component decorator [OK]
Common Mistakes:
MISTAKES
  • Trying to set changeDetection inside the constructor
  • Using a non-existent @ChangeDetection decorator
  • Calling methods on ChangeDetectorRef to set strategy

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes