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
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;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With