How to scroll page to Top on route change.



Add bellow code in app.component.ts file. this.router.events.subscribe((evt) => {
if (!(evt instanceof NavigationEnd)) {
return;
}
window.scrollTo(0, 0)
});


app.component.ts

import { Component } from '@angular/core';
import { Router, NavigationEnd } from '@angular/router';

@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
title = 'AngularCrud';

constructor(private router: Router) { }

ngOnInit() {
this.router.events.subscribe((evt) => {
if (!(evt instanceof NavigationEnd)) {
return;
}
window.scrollTo(0, 0)
});
}
}

Comments

Popular posts from this blog

how to save images with angular nodejs

How to add splash screen and app icon with ionic capacitor angular android app

How to export data to excel sheet with colors and style in angular.