简体   繁体   中英

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. However between "page loads" the DOM is not automatically scrolling to the top of the new page.

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. 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. Have I done something stupid in my code or does everyone just have to use $anchorScroll for every view of their SPA?

您应该尝试$ anchorScroll服务。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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