How to access mouse coordinates in my directive (in Angular 2 for Dart)?


I’m using latest Angular 2 for Dart (version 3.1). In my custom directive implementation I can define mouse events with annotations like this:

void onMouseEnter() {
   //But how to access mouse coordinates here (MouseEvent object) ???

How can I access mouse coordinate on the object that I interacted with using mouse cursor?


You should add an $event argument to @HostListener annotation like this:

@HostListener('mouseenter', const [r'$event'])
void onMouseEnter(MouseEvent e) {
   //MouseEnter coordinates are following
   print("X = " + e.client.x.toString());
   print("Y = " + e.client.y.toString());

Answered By – ainla

Answer Checked By – Clifford M. (FlutterFixes Volunteer)

Leave a Reply

Your email address will not be published.