Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular Renderer2 listen - cannot attach to touchstart and mousedown

Tags:

I am trying to create a listener on a component attached to either mousedown (for desktops) and touchstart (for mobile)

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.

like image 318
Dawid Adach Avatar asked Dec 15 '17 08:12

Dawid Adach


1 Answers

It's not supported via Renderer2. See: https://github.com/angular/angular/issues/12751

Use this:

Observable.merge(
  Observable.fromEvent(this.el.nativeElement, 'mousedown'),
  Observable.fromEvent(this.el.nativeElement, 'touchstart')
)
like image 156
Dawid Winiarczyk Avatar answered Sep 19 '22 13:09

Dawid Winiarczyk