How do I keep the browser scrollbar at the top by loading a new angled page?

Asked

Viewed 259 times

1

I’m using modules created with Ode and Angular, by project specification we had to take the # of the navigation. However, when I click on a link that is on the footer and loads another page the browser scroll bar continues on the footer and does not go to the top as a traditional navigation. Can anyone tell me if there are any settings that solve this problem?

1 answer

1

With ngRouter or uiRouter, you can monitor route changes. And with each change or in certain changes, apply scroll to position 0.

Example: (for uiRouter)

angular.module('app').run(['$rootScope', function ($rootScope)]{
    $rootScope.$on('$stateChangeStart', function () {
        window.scrollTop(0,0);
    })
});

If using ngRouter change the $stateChangeStartfor $routeChangeStart

Browser other questions tagged

You are not signed in. Login or sign up in order to post.