diff --git a/frontend/src/app/app.component.ts b/frontend/src/app/app.component.ts index 8f665bb..c0a7f2a 100644 --- a/frontend/src/app/app.component.ts +++ b/frontend/src/app/app.component.ts @@ -1,4 +1,7 @@ import { AfterViewInit, Component, ElementRef, ViewChild } from '@angular/core'; +import { NavigationEnd, Router } from '@angular/router'; +import { filter } from 'rxjs'; + import PerfectScrollbar from 'perfect-scrollbar'; @Component({ @@ -7,12 +10,25 @@ import PerfectScrollbar from 'perfect-scrollbar'; styleUrl: './app.component.css', }) export class AppComponent implements AfterViewInit { + title = 'ShowZ'; + @ViewChild('scrollContainer', { static: true }) scrollContainer!: ElementRef; private ps!: PerfectScrollbar; - title = 'ShowZ'; + constructor(private router: Router) {} ngAfterViewInit() { this.ps = new PerfectScrollbar(this.scrollContainer.nativeElement); + + this.router.events + .pipe(filter(event => event instanceof NavigationEnd)) + .subscribe(() => { + this.scrollToTop(); + }); + } + + scrollToTop() { + this.scrollContainer.nativeElement.scrollTop = 0; + this.ps.update(); } }