Bird
0
0

Given this component with OnPush:

medium📝 component behavior Q4 of 15
Angular - Change Detection
Given this component with OnPush:
@Component({
  selector: 'app-sample',
  changeDetection: ChangeDetectionStrategy.OnPush
})
export class SampleComponent {
  @Input() data: string;
}

What triggers Angular to check this component for changes?
AWhen any event happens anywhere in the app.
BWhen the <code>data</code> input reference changes.
COnly when manually calling <code>detectChanges()</code>.
DWhen the component's internal variables change.
Step-by-Step Solution
Solution:
  1. Step 1: Understand OnPush triggers

    OnPush triggers change detection when input references change or events inside the component occur.
  2. Step 2: Analyze options

    Any event anywhere describes default strategy; manual detectChanges() is not automatic; internal changes are not detected automatically. Input reference change matches OnPush trigger.
  3. Final Answer:

    When the data input reference changes. -> Option B
  4. Quick Check:

    OnPush triggers = input reference changes [OK]
Quick Trick: OnPush checks on input reference changes [OK]
Common Mistakes:
MISTAKES
  • Thinking all app events trigger OnPush
  • Believing internal variable changes trigger detection
  • Assuming manual detectChanges is always needed

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes