I manually add and remove Eventlisteners on DOM-Elements for performance reasons from the ngZone in Angular. My implementation seems fine and I'm currently try to refactor code to keep it DRY and more readable. Now, my question is if there is a way to pass multiple DOM-Elements to the Renderer2.listen() function. So basically I want to do something like this:
this._unlisten['mouseup'] = this._renderer.listen(
this.elementView.nativeElement, // <- Can I pass more elements than just elementView?
'mouseup',
(event) => {
unlistenToTheEventOnSeveralElements(event)
}
)
Thanks in advance for any ideas or suggestions.
From an Angular documentation:
If you need to listen to a multiple elements being clicked you should use rxjs fromEvent and merge all events with merge like this:
Here is the example app so you can see it in action: stackblitz