Scroll Top in angular2
angular, angular2-routing, javascript, typescript
Solution
import like this,
import { Inject} from "@angular/core";
import { DOCUMENT } from '@angular/platform-browser';
In your constructor add this,
constructor(@Inject(DOCUMENT) private document: Document) { }
Then you can set the scroll anywhere like this,
this.document.body.scrollTop = 0;
Problem
I am working on angular2 web application where I need help on the following. My page consists of multiple components. I want to scroll top of the page when user clicks a button. I tried `document.body.scrollTop = 0;` but this is not working in Chrome. I Tried document.documentElement.scrollTop=0;window.scrollTo(0, 0); but not working