What will be displayed after clicking the button three times?
medium
A. Count: 0
B. Count: 1
C. Count: 3
D. Count: undefined
Solution
Step 1: Understand event binding effect on count
Each click triggers the increment() method, which adds 1 to count.
Step 2: Calculate count after three clicks
Starting at 0, after 3 clicks: 0 + 3 = 3.
Final Answer:
Count: 3 -> Option C
Quick Check:
3 clicks increment count to 3 [OK]
Hint: Each click runs increment, adding 1 to count [OK]
Common Mistakes:
Thinking count resets on each click
Confusing event binding with property binding
Ignoring the initial count value
4. Identify the error in this Angular template snippet:
<button click="doSomething()">Press</button>
medium
A. The button tag is invalid.
B. The method name should be in square brackets.
C. The event name should be in curly braces.
D. Missing parentheses around the event name for binding.
Solution
Step 1: Check event binding syntax
Angular requires parentheses around event names to bind events, e.g., (click).
Step 2: Identify missing parentheses
The snippet uses click="doSomething()" without parentheses, so Angular won't bind the event.
Final Answer:
Missing parentheses around the event name for binding. -> Option D
Quick Check:
Event binding needs parentheses = A [OK]
Hint: Event binding always needs parentheses around event name [OK]
Common Mistakes:
Omitting parentheses around event name
Using square or curly braces instead of parentheses
Assuming HTML attribute alone binds event
5. You want to call a method submitForm() only when the user presses the Enter key inside an input box. Which Angular event binding syntax correctly achieves this?
<input (??? )="submitForm()" />
hard
A. (keyup)
B. (keyup.enter)
C. (keydown)
D. (keypress.enter)
Solution
Step 1: Understand Angular key event filtering
Angular supports event filtering like (keyup.enter) to listen only for Enter key on keyup.
Step 2: Choose the correct event with key filter
(keyup.enter) triggers submitForm() only when Enter is released, which is the recommended approach.
Final Answer:
(keyup.enter) -> Option B
Quick Check:
Use (keyup.enter) to detect Enter key [OK]
Hint: Use (keyup.enter) to trigger on Enter key press [OK]
Common Mistakes:
Using (keydown) without key filter triggers on all keys
Using (keyup) triggers on all keys, not just Enter
Using deprecated (keypress.enter) event
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.