简体   繁体   English

Angular Renderer2听 - 无法附加到touchstart和mousedown

[英]Angular Renderer2 listen - cannot attach to touchstart and mousedown

I am trying to create a listener on a component attached to either mousedown (for desktops) and touchstart (for mobile) 我正在尝试在连接到mousedown(用于桌面)和touchstart(用于移动设备)的组件上创建一个侦听器

this.renderer.listen(this.el.nativeElement, 'mousedown touchstart', (event: any) => {} 

However, when I run it like above it doesn't work. 但是,当我像上面那样运行时,它不起作用。 When I have 1 option (either mousedown or touchstart) it working fine for given event type, however as soon as I add the second option it doesn't react at all. 当我有1个选项(mousedown或touchstart)时,它对于给定的事件类型工作正常,但是只要我添加第二个选项它就完全没有反应。

It's not supported via Renderer2 . Renderer2不支持它。 See: https://github.com/angular/angular/issues/12751 请参阅: https//github.com/angular/angular/issues/12751

Use this: 用这个:

Observable.merge(
  Observable.fromEvent(this.el.nativeElement, 'mousedown'),
  Observable.fromEvent(this.el.nativeElement, 'touchstart')
)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM