jitenderd
jitenderd

Reputation: 198

type for $event rather than any?

I am using angular $event in one of my function as a parameter. I don't want to use 'any' type for evt in function definition. what is the preferable alternative for evt?

Html

<button class="edit-button" (click)="invokeEdit($event)">Edit</button>

TypeScript

public invokeEdit(evt: any): void {
    evt.stopPropagation();
}

Upvotes: 0

Views: 283

Answers (1)

Sharma Vikram
Sharma Vikram

Reputation: 2470

You can use the mouse event MouseEvent interface. Please check the below link for more information.

Reference one

Reference two

Html:-

<button (click)="invokeEdit($event)" type="submit" mat-raised-button color="default">Edit</button> 

TypeScript:-

public invokeEdit(event: MouseEvent): void {          
 console.log(event); 
 event.stopPropagation();
}

Upvotes: 2

Related Questions