如何在我的指令中访问鼠标坐标(在 Angular 2 for Dart 中)?

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

我正在使用最新的 Angular 2 for Dart(版本 3.1)。在我的自定义指令实现中,我可以定义 mouse events with annotations like this:

@HostListener('mouseenter')
void onMouseEnter() {
   do_something_here();
   //But how to access mouse coordinates here (MouseEvent object) ???
}

如何访问我使用鼠标光标与之交互的对象上的鼠标坐标?

您应该像这样向 @HostListener 注释添加一个 $event 参数:

@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());
}