Event Binding in Angular 8
In Angular 8, event binding is used to handle the events raised by the user actions like button click, mouse movement, keystrokes, etc. When the DOM event happens at an element(e.g. click, keydown, keyup), it calls the specified method in the particular component.
Using Event Binding we can bind data from DOM to the component and hence can use that data for further purposes.
< element (event) = function() >
- Define a function in the app.component.ts file which will do the given task.
- In the app.component.html file, bind the function to the given event on the HTML element.
Example 1: Using click event on the input element.
Example 2: Using keyup event on the input element.