Answers for "angular route change scroll to top"

3

angular route change scroll to top

RouterModule.forRoot(appRoutes, { scrollPositionRestoration: 'enabled' })
Posted by: Guest on October-31-2020
-2

scroll to top when routing angular

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)
        });
    }
}
Posted by: Guest on July-01-2020

Code answers related to "angular route change scroll to top"

Code answers related to "Javascript"

Browse Popular Code Answers by Language