0

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" />
user3226932
  • 2,042
  • 6
  • 39
  • 76

2 Answers2

3

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);
});
Tareq El-Masri
  • 2,413
  • 15
  • 23
1

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):

Community
  • 1
  • 1
TWright
  • 1,853
  • 18
  • 25