How do I keep the browser scroll bar at the top when loading a new page with angular?

0

I'm using modules created with node and angular, by specification of the project we had to take the # navigation. However, when I click on a link that is in the footer and loads another page the browser scroll bar remains in the footer and does not go to the top as a traditional navigation. Can anyone tell me if there is any setting that solves this problem?

    
asked by anonymous 21.12.2016 / 14:54

1 answer

0

With ngRouter or uiRouter, you can monitor route changes. And with each change or in certain changes, apply the 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 $stateChangeStart to $routeChangeStart

    
23.12.2016 / 16:18