javascript / beginner
Snippet
Handling User Clicks with Event Binding
Event binding allows you to listen for and respond to user actions, such as clicks, by wrapping the event name in parentheses.
snippet.js
1
2
<!-- component.html --><button (click)="showAlert()">Click Me</button>
angular
Breakdown
1
(click)
The parentheses indicate a one-way data flow from the view (HTML) to the component class.
2
"showAlert()"
This is the method defined in your TypeScript class that will be executed when the button is clicked.