⊗jsagPmLpOE 39 of 97 menu

Event object in event handler in Angular template

In event handlers, you can get an object Event. To do this, you need to pass a special variable $event (with a dollar sign at the beginning) to the parameter of the bound method:

<button (click)="show($event)"> button </button>

Let's get the passed object in the class method:

export class AppComponent { public show(event: MouseEvent): void { console.log(event); } }

On click, get an object with an event and output it to the console.

Get the coordinates of the click on the screen.

enru