Bird
0
0

Which of the following is the correct syntax to bind a click event in an Angular template?

easy📝 Syntax Q12 of 15
Angular - Templates and Data Binding
Which of the following is the correct syntax to bind a click event in an Angular template?
A<code><button <click>="doSomething()">Click</button></code>
B<code><button (click)="doSomething()">Click</button></code>
C<code><button [click]="doSomething()">Click</button></code>
D<code><button {click}="doSomething()">Click</button></code>
Step-by-Step Solution
Solution:
  1. Step 1: Recall Angular event binding syntax

    Angular uses parentheses around event names to bind events, like (click).
  2. Step 2: Check each option

    Only <button (click)="doSomething()">Click</button> uses the correct (click) syntax with quotes and parentheses.
  3. Final Answer:

    <button (click)="doSomething()">Click</button> -> Option B
  4. Quick Check:

    Event binding uses (event) syntax [OK]
Quick Trick: Event bindings always use parentheses (event) [OK]
Common Mistakes:
  • Using square brackets instead of parentheses
  • Using curly braces instead of parentheses
  • Missing quotes around the method call

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes