I'm currently having the following problem: It's an Angular project that is still giving me a few problems on the mobile view.
I have a list of messages. As soon as I scroll up in this list, I want a button to be displayed so that I can get back to the bottom of the list. On the desktop view this works well (scroll event). For the mobile view I use the "touchmove" event (because the scroll-event doesn't fire). Based on both events, the scroll distances are calculated and the button is triggered. I use the "fromEvent"-Method of rxjs.
However, there are more divs (childs) inside the list div (parent) and my "touchmove" event (TouchEvent) always refers to the innermost element.
Is there any way to always refer to the parent element when a touchmove event is triggered?
TypeScript:
@ViewChild('messages', {static: true}) messagesElementRef: ElementRef;
// ...
fromEvent(this.messagesElementRef.nativeElement, 'touchmove', {passive: true}).pipe(auditTime(500))
.subscribe((event: any) => this.scrollEventCalculator(event));
HTML:
<div #messages class="messages">
<ng-container ...>
<div *ngFor="let message of messages$ | async as messages ...">
<ng-container ...>
<custom-message [message]="message"></message>
</ng-container>
</div>
</ng-container>
</div>
As soon as I'm in the mobile view, the Chrome DevTools always show me the innermost DOM element as target. I would have thought that the "messages" div is accessed, since the @ViewChild is defined for it.