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" />

2 Answers 2

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);
});
Sign up to request clarification or add additional context in comments.

Comments

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.