Angular2如何在用户交互时滚动到窗口顶部 [英] Angular2 How to scroll to top of window on user interaction

查看:77
本文介绍了Angular2如何在用户交互时滚动到窗口顶部的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我很难弄清楚如何在用户交互(例如单击项目)时将页面滚动到窗口顶部.在AngularJS中,我可以使用$window.scrollTo(0, 0); 我没有使用Angular2 Router,因此需要类似afor提及的$window

so i am having hard time to figure out how to scroll page to top of window upon user interaction (like click on item). In AngularJS i could use $window.scrollTo(0, 0); I am not using Angular2 Router so need something like aformentioned $window

任何帮助将不胜感激.

Any help would be appreciated.

推荐答案

如果您只想使用角度2(

You can use the javascript window object or refer to this link if you want to do it purely in angular 2(Angular2 - How to inject window into an angular2 service):

window.scrollTo(0,0);

这篇关于Angular2如何在用户交互时滚动到窗口顶部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆