Karl B.
Karl B.

Reputation: 263

AngularJS UI-Router scroll to top after state change

My page should scroll to top again after i change the page.
I have an angular1.6 page with page transitions & ui-router, so i cant use <div ui-view="main" autoscroll="true"></div>. I tried the following code but its not even executing the console.log :/ :

 angular.module("App", ["ngAnimate", "ui.router", "vcRecaptcha"]).run(["$rootScope", "$state", function(a, b) {
        a.$on('$stateChangeSuccess',function(){ 
            window.scrollTo(0,0);
            console.log("foo");
        })

    }])

I tried routeChangeSuccess too ... any ideas?
Thanks in advance

Upvotes: 1

Views: 713

Answers (1)

Youness HARDI
Youness HARDI

Reputation: 522

If you are using the new ui-router (v1.0.0), the $stateChange* events will not work. You must use $transitions.on* hooks from now on.

Upvotes: 2

Related Questions