Winkelrolle nach oben
scrollToTop(){
window.scroll(0,0);
}
ChernobylBob
scrollToTop(){
window.scroll(0,0);
}
RouterModule.forRoot(appRoutes, { scrollPositionRestoration: 'enabled' })
//inside the app.component.html add (activate):
<router-outlet (activate)="onActivate($event)"></router-outlet>
//inside app.component.ts, add inside the class of the component:
export class AppComponent {
onActivate(event) {
window.scroll(0,0);
//or document.body.scrollTop = 0;
//or document.querySelector('body').scrollTo(0,0)
}
}
import { Component, OnInit } from '@angular/core';
import { Router, NavigationEnd } from '@angular/router';
@Component({
selector: 'my-app',
template: '<ng-content></ng-content>',
})
export class MyAppComponent implements OnInit {
constructor(private router: Router) { }
ngOnInit() {
this.router.events.subscribe((evt) => {
if (!(evt instanceof NavigationEnd)) {
return;
}
window.scrollTo(0, 0)
});
}
}