AngularJS + Safari: Force page to scroll to top when pages switch

后端 未结 9 1924
深忆病人
深忆病人 2021-02-07 00:20

I am having an odd, safari-only scrolling behavior using AngularJS.

Whenever the user flips between pages, the pages are being changed as if they are AJAX. I understand

9条回答
  •  春和景丽
    2021-02-07 00:33

    you can use this:

    .run(["$rootScope", "$window", '$location', function($rootScope, $window,  $location) {
    
        $rootScope.$on('$routeChangeStart', function(evt, absNewUrl, absOldUrl){
            $window.scrollTo(0,0);    //scroll to top of page after each route change
    }}])
    

    or for tab switches you can use the $window.scrollTo(0,0); in your controller

提交回复
热议问题