Angular: disable scroll up when view changes

Say I have a big title, so the ng-view directive is not listed on the page. before this ng-view, I have a kind of menu that starts angular routing and therefore changes the view. My problem is that at any time when the routing starts, the page keeps scrolling up so that the partial part is not in the viewport.

here is my routing:

 angular.module('portfolio', []) .config(function ($routeProvider, $anchorScrollProvider) { $anchorScrollProvider.disableAutoScrolling(); $routeProvider .when('', { templateUrl: 'portfolio/index.html', controller: 'PortfolioListCtrl' }) .when('/portfolio/:project', { templateUrl: 'portfolio/detail.html', controller: 'PortfolioDetailCtrl' }) .otherwise({redirectTo: ''}); }); 

I have $anchorScrollProvider.disableAutoScrolling(); , this does not work.

Anyone have an idea?

+7
source share
1 answer

The docs are a bit confusing in this matter, I remember that I had the same problem. Apparently, ng-view uses the $ anchorScroll service, so you can disable it by simply overwriting it in your module:

 angular.module('portfolio').value('$anchorScroll', angular.noop); 
+6
source

All Articles