Changing route doesn't scroll to top in the new page

后端 未结 18 2079
北恋
北恋 2020-11-29 15:11

I've found some undesired, at least for me, behaviour when the route changes. In the step 11 of the tutorial http://angular.github.io/angular-phonecat/step-11/app/#/phon

18条回答
  •  感情败类
    2020-11-29 15:21

    None of the answer provided solved my issue. I am using an animation between views and the scrolling would always happen after the animation. The solution I found so that the scrolling to the top happen before the animation is the following directive:

    yourModule.directive('scrollToTopBeforeAnimation', ['$animate', function ($animate) {
        return {
            restrict: 'A',
            link: function ($scope, element) {
                $animate.on('enter', element, function (element, phase) {
    
                    if (phase === 'start') {
    
                        window.scrollTo(0, 0);
                    }
    
                })
            }
        };
    }]);
    

    I inserted it on my view as follows:

提交回复
热议问题