简体   繁体   English

Angular加载的新视图未在视图顶部加载

[英]New views loaded with Angular not loading at the top of the view

I am using hash routing in Angular.js to navigate between my different HTML views. 我在Angular.js中使用哈希路由在不同的HTML视图之间导航。 However between "page loads" the DOM is not automatically scrolling to the top of the new page. 但是,在“页面加载”之间,DOM不会自动滚动到新页面的顶部。

If the user is 50% down one page and navigates to a page of similar length, the new page will load 50% down as well. 如果用户在一页上浏览了50%,并导航到相似长度的页面,则新页面也将向下加载50%。 This is forcing me to call 这迫使我打电话

window.scrollTo(0, 0); 

on each of my pages. 在我的每一页上。 I have just looked into Angular's $anchorScroll and it solves the problem too but it seems to me the default behaviour should be to scroll to the top of each new view. 我刚刚研究了Angular的$ anchorScroll,它也解决了这个问题,但是在我看来,默认行为是滚动到每个新视图的顶部。 Have I done something stupid in my code or does everyone just have to use $anchorScroll for every view of their SPA? 我是否在代码中做了一些愚蠢的事情,还是每个人都只需要对$ SPA的每个视图都使用$ anchorScroll?

您应该尝试$ anchorScroll服务。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM