Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Web Technology by (47.6k points)

I've found some undesired, at least for me, behaviour when the route changes. In step 11 of the tutorial http://angular.github.io/angular-phonecat/step-11/app/#/phones you can see the list of phones. If you scroll to the bottom and click on one of the latest, you can see that the scroll isn't at the top, instead is kind of in the middle.

I've found this in one of my apps too and I was wondering how can I get this to scroll to the top. I can do it manually, but I think that there should be another elegant way to do this which I don't know.

So, is there an elegant way to scroll to the top when the route changes?

1 Answer

0 votes
by (106k points)

Yes there is a way to scroll to the top when the route changes you can use the below-mentioned code for this:-

$rootScope.$on("$routeChangeSuccess",function(event, currentRoute, previousRoute) { 

window.scrollTo(0, 0); 

});

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

Browse Categories

...