0 day streak
javascript / beginner
Snippet

Handling User Clicks

Event binding in Angular lets you listen for and respond to user actions like button clicks by calling a function in your TypeScript class.

snippet.js
javascript
1
2
3
4
5
6
7
8
export class ActionComponent {
onSave() {
console.log('Data saved successfully!');
}
}
<!-- Template -->
<button (click)="onSave()">Save</button>
angular
Breakdown
1
onSave() { ... }
A method defined in the class to execute logic when called.
2
(click)="onSave()"
The parentheses indicate event binding, linking the DOM click event to the component method.