Skip to content

Instantly share code, notes, and snippets.

@sserbest
Created September 15, 2017 19:53
Show Gist options
  • Save sserbest/95dcbecf98bdf7271e29dbb893e339c2 to your computer and use it in GitHub Desktop.
Save sserbest/95dcbecf98bdf7271e29dbb893e339c2 to your computer and use it in GitHub Desktop.
Automatically Scroll To Top Of Page With UI-Router In AngularJS
angular.module("app",[
'ngRoute',
'ui.router',
'ngMaterial',
'ngSanitize',
'ngCookies'
])
.config(function($stateProvider, $urlRouterProvider,$locationProvider,$uiViewScrollProvider){
$uiViewScrollProvider.useAnchorScroll();
})
.run(function($rootScope,$location,$stateParams, $anchorScroll){
$rootScope.$on('$stateChangeSuccess', function(event, toState){
if($stateParams.scrollTo){
$location.hash($stateParams.scrollTo);
$anchorScroll();
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment