How to make Angular 2 remember scroll position?

孤人 提交于 2019-12-10 11:22:27

问题


I'm on page 1, I scroll halfway through the page and then click a link that brings me to page 2 through the Angular router. When I hit the "back" button, I'd like page 1 to be scrolled halfway down, just like it was before I left that page.

What is the easiest way to do that?


回答1:


Save to localStorage scroll position in ngOnDestroy(), and restore it in ngOnInit()



来源:https://stackoverflow.com/questions/42439745/how-to-make-angular-2-remember-scroll-position

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!