Reputation: 2252
I'm using Angular's ui-router but having a problem where when I click on a new view, the page doesn't start at the top but where it was. I set autoscroll to true in my ui-view like what others suggested but it still isn't working. I'm not sure what the reason is for it not working.
<ui-view autoscroll="true" />
Upvotes: 0
Views: 1689
Reputation: 1849
As you will see at this other SO Post '$routeChangeSuccess' will not work. You need to change the code to look like this:
$scope.$on('$stateChangeSuccess', function () {
window.scrollTo(0, 0);
});
Helpful UI-Router references (some gleaned from the referred-to SO Post):
Upvotes: 1
Reputation: 2573
The default option is true, maybe there's something preventing the autoscroll from firing, we need more code. Also you can make a custom code that'll work. Something like this
$scope.$on('$routeChangeSuccess', function () {
window.scrollTo(0, 0);
});
Upvotes: 3