Bird
0
0

Given this Angular component:

medium📝 component behavior Q4 of 15
Angular - Change Detection
Given this Angular component:
@Component({ selector: 'app-counter', template: '{{count}}', changeDetection: ChangeDetectionStrategy.Default }) export class CounterComponent { count = 0; increase() { this.count++; } }

What will Angular do when increase() is called?
AAngular will not update the view unless manually triggered.
BAngular will detect the change and update the view automatically.
CAngular will update the view only if OnPush strategy is set.
DAngular will throw an error due to missing lifecycle hook.
Step-by-Step Solution
Solution:
  1. Step 1: Recognize default strategy behavior

    With ChangeDetectionStrategy.Default, Angular runs change detection automatically on events.
  2. Step 2: Effect of calling increase()

    Calling increase() changes 'count', triggering Angular to update the view.
  3. Final Answer:

    Angular will detect the change and update the view automatically. -> Option B
  4. Quick Check:

    Default strategy auto-updates view on state change [OK]
Quick Trick: Default strategy auto-updates view on state change [OK]
Common Mistakes:
MISTAKES
  • Assuming manual update needed
  • Confusing with OnPush behavior
  • Expecting errors without lifecycle hooks

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes