"scroll to top angular" Code Answer's
You're definitely familiar with the best coding language TypeScript that developers use to develop their projects and they get all their queries like "scroll to top angular" answered properly. Developers are finding an appropriate answer about scroll to top angular related to the TypeScript coding language. By visiting this online portal developers get answers concerning TypeScript codes question like scroll to top angular. Enter your desired code related query in the search bar and get every piece of information about TypeScript code related question on scroll to top angular.
angular scroll to top
scrollToTop(){
window.scroll(0,0);
}
scroll to top angular
//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)
}
}
Source: stackoverflow.com
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)
});
}
}
Source: stackoverflow.com
All those coders who are working on the TypeScript based application and are stuck on scroll to top angular can get a collection of related answers to their query. Programmers need to enter their query on scroll to top angular related to TypeScript code and they'll get their ambiguities clear immediately. On our webpage, there are tutorials about scroll to top angular for the programmers working on TypeScript code while coding their module. Coders are also allowed to rectify already present answers of scroll to top angular while working on the TypeScript language code. Developers can add up suggestions if they deem fit any other answer relating to "scroll to top angular". Visit this developer's friendly online web community, CodeProZone, and get your queries like scroll to top angular resolved professionally and stay updated to the latest TypeScript updates.