In angular,
This is script
<button (click)="onClick($event)"> Greet </button>
<button (click)="greeting='welcome' "> Greet </button>
{{greeting}}
This is event Logic
public greeting ="";
onClick(event) {
console.log(event);
this.greeting ='welcome';
}
CodePudding user response:
Some alternatives you can use:
onClick(event: Event) {}
onClick(event: MouseEvent) {}
Also, if you are not using the parameter event for anything, you can remove it.
onClick() { ... }
CodePudding user response:
On click of that button on console, we can see PoinerEvent { isTrusted": true }
So in addition to MouseEvent
or Event
you can also use:
onClick(event: PointerEvent) {}
Check the docs at PointerEvent MDN. "This interface inherits properties from MouseEvent and Event."