Created
June 23, 2015 09:35
-
-
Save larvanitis/2576c058f3d8202d5a3a to your computer and use it in GitHub Desktop.
Event logging for AngularJS $location and ui-router $state change.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
angular.module('myModule').run(function ($rootScope, $state) { | |
/* ENTRY EVENTS */ | |
$rootScope.$on('$locationChangeStart', function (event, toUrl, fromUrl, toHistoryState, fromHistoryState) { | |
console.groupCollapsed('$locationChangeStart'); | |
console.debug('event:', event); | |
console.debug('toUrl:', toUrl); | |
console.debug('fromUrl:', fromUrl); | |
console.debug('toHistoryState:', toHistoryState); | |
console.debug('fromHistoryState:', fromHistoryState); | |
console.groupEnd('$locationChangeStart'); | |
}); | |
$rootScope.$on('$stateChangeStart', function (event, toState, toParams, fromState, fromParams) { | |
console.groupCollapsed('$stateChangeStart'); | |
console.debug('event:', event); | |
console.debug('toState:', toState); | |
console.debug('toParams:', toParams); | |
console.debug('fromState:', fromState); | |
console.debug('fromParams:', fromParams); | |
console.groupEnd('$stateChangeStart'); | |
}); | |
/* SUCCESS EVENTS */ | |
$rootScope.$on('$locationChangeSuccess', function (event, toUrl, fromUrl, toHistoryState, fromHistoryState) { | |
console.groupCollapsed('$locationChangeSuccess'); | |
console.debug('event:', event); | |
console.debug('toUrl:', toUrl); | |
console.debug('fromUrl:', fromUrl); | |
console.debug('toHistoryState:', toHistoryState); | |
console.debug('fromHistoryState:', fromHistoryState); | |
console.groupEnd('$locationChangeSuccess'); | |
}); | |
$rootScope.$on('$stateChangeSuccess', function (event, toState, toParams, fromState, fromParams) { | |
console.groupCollapsed('$stateChangeSuccess'); | |
console.debug('event:', event); | |
console.debug('toState:', toState); | |
console.debug('toParams:', toParams); | |
console.debug('fromState:', fromState); | |
console.debug('fromParams:', fromParams); | |
console.groupEnd('$stateChangeSuccess'); | |
console.debug('\n'); | |
}); | |
/* ERROR EVENTS */ | |
$rootScope.$on('$stateChangeError', function (event, toState, toParams, fromState, fromParams) { | |
console.groupCollapsed('$stateChangeError'); | |
console.debug('event:', event); | |
console.debug('toState:', toState); | |
console.debug('toParams:', toParams); | |
console.debug('fromState:', fromState); | |
console.debug('fromParams:', fromParams); | |
console.groupEnd('$stateChangeError'); | |
console.debug('\n'); | |
}); | |
$rootScope.$on('$stateNotFound', function (event, unfoundState, fromState, fromParams) { | |
console.groupCollapsed('$stateNotFound'); | |
console.debug('event:', event); | |
console.debug('unfoundState:', unfoundState); | |
console.debug('fromState:', fromState); | |
console.debug('fromParams:', fromParams); | |
console.groupEnd('$stateNotFound'); | |
console.debug('\n'); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment