Issue
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:
@HostListener('mouseenter')
void onMouseEnter() {
do_something_here();
//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?
Solution
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)