Angular 4: programmatically go to the top of the page

Does anyone know how to use Angular 4 and programmatically scroll the page at the top? My use case is that I have a search page and the input is at the top, and links to other pages of the search results are at the bottom. When the user clicks the link (2,3,4 ...), I would like the page to fill in new results (functionality completed), and then scroll up the page to show the results (this function is not complete).

I see that this is possible with jQuery ( Scroll to top of page ), but I was wondering if there is a way to stay in Angular 4.

Any help is greatly appreciated.

+4
source share
2 answers

Just use the built-in JavaScript window.scrollTo method - going through 0,0 will scroll the page in the upper left corner.

window.scrollTo(xCoord, yCoord);

Parameters

  • xCoord is a pixel along the horizontal axis.
  • yCoord is a pixel along the vertical axis.
+8
source

You do not need an additional library for this. A standard HTML tag will suffice if you use the syntax below

<div id="place">
   Something.....
</div>

<a target="#place">Click Here .....!</a>
+1
source

Source: https://habr.com/ru/post/1683599/


All Articles