Bird
0
0

Given this component template snippet:

medium📝 component behavior Q13 of 15
Angular - Components
Given this component template snippet:
<button (click)="increment()">Add</button>
<p>Count: {{ count }}</p>

And the component code:
count = 0;
increment() { this.count++; }

What will be displayed after clicking the button three times?
ACount: 3
BCount: 0
CCount: 1
DCount: undefined
Step-by-Step Solution
Solution:
  1. Step 1: Understand the initial state and method

    The count starts at 0. Each click calls increment(), which adds 1 to count.
  2. Step 2: Calculate count after three clicks

    After 3 clicks, count = 0 + 3 = 3, so template shows 'Count: 3'.
  3. Final Answer:

    Count: 3 -> Option A
  4. Quick Check:

    3 clicks increment count to 3 [OK]
Quick Trick: Click calls method that adds 1 each time [OK]
Common Mistakes:
  • Thinking count resets after each click
  • Confusing event binding syntax
  • Ignoring the initial count value

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes