如何必须听取聚合物手势事件

时间:2022-04-22 23:59:59

I built a behavior to make Polymer elements draggable, but when I add the event listener imperatively it isn't called.

我构建了一个使Polymer元素可拖动的行为,但是当我强制添加事件监听器时,它不会被调用。

abstract class DraggableBehavior implements PolymerBase, dom.Element {
  void attached() {
    super.attached();
    this.on['track'].listen(_dragHandler);
  }

  void _dragHandler(dom.CustomEvent event, [_]) {
    print(event.type);
  }
}

As soon as I add on-track="someOtherTrackHandler" (note the different name of the event handler) dragHandler is called just fine.

只要我添加on-track =“someOtherTrackHandler”(注意事件处理程序的不同名称),就会调用dragHandler。

It seems Polymer enables polymer-gesture events only when event handlers are added imperatively.

看起来,只有当必须添加事件处理程序时,Polymer才能启用聚合物手势事件。

Is there a workaround?

有解决方法吗?

1 个解决方案

#1


0  

Using listen from the Polymer API (PolymerBase) instead works

使用Polymer API(PolymerBase)的listen代替工作

void attached() {
  super.attached();
  listen(this, 'track', 'dragHandler');
}

@reflectable
void dragHandler(dom.CustomEvent event, [_]) {
  print(event.type);
}

#1


0  

Using listen from the Polymer API (PolymerBase) instead works

使用Polymer API(PolymerBase)的listen代替工作

void attached() {
  super.attached();
  listen(this, 'track', 'dragHandler');
}

@reflectable
void dragHandler(dom.CustomEvent event, [_]) {
  print(event.type);
}