AngularJS UI-Router event when changing route

David Dury picture David Dury · Apr 11, 2015 · Viewed 8.2k times · Source

Using ngRoute once can hook up in event: $routeChangeStart and do different actions ...

 app.run(function ($rootScope, $location) {
    $rootScope.$on("$routeChangeStart", function (event, next, current) {
    ................

Is it possible to achieve the same using UI-Router?

Answer

karaxuna picture karaxuna · Apr 11, 2015

Yes it's possible:

$rootScope.$on("$stateChangeStart",
    function (event, toState, toParams, fromState, fromParams) {