Created
June 9, 2016 14:50
-
-
Save vigor-rus/5b8ce71eddb663c919c4eab894c0632b to your computer and use it in GitHub Desktop.
simple ui-router logger snippet
This file contains hidden or 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
| (function() { | |
| 'use strict'; | |
| //http://stackoverflow.com/a/26086754/5807080 | |
| angular | |
| .module('blocks.uirouterlogger') | |
| .factory('uirouterlogger', uirouterlogger); | |
| uirouterlogger.$inject = ['$rootScope', '$log']; | |
| function uirouterlogger($rootScope, $log) { | |
| var handler = {active: false}; | |
| handler.toggle = function () { | |
| handler.active = !handler.active; | |
| }; | |
| $rootScope.$on('$stateChangeStart', function (event, toState, toParams, fromState, fromParams) { | |
| if (handler.active) { | |
| $log.debug("$stateChangeStart --- event, toState, toParams, fromState, fromParams", arguments); | |
| } | |
| }); | |
| $rootScope.$on('$stateChangeError', function (event, toState, toParams, fromState, fromParams, error) { | |
| if (handler.active) { | |
| $log.debug("$stateChangeError --- event, toState, toParams, fromState, fromParams, error", arguments); | |
| } | |
| }); | |
| $rootScope.$on('$stateChangeSuccess', function (event, toState, toParams, fromState, fromParams) { | |
| if (handler.active) { | |
| $log.debug("$stateChangeSuccess --- event, toState, toParams, fromState, fromParams", arguments); | |
| } | |
| }); | |
| $rootScope.$on('$viewContentLoading', function (event, viewConfig) { | |
| if (handler.active) { | |
| $log.debug("$viewContentLoading --- event, viewConfig", arguments); | |
| } | |
| }); | |
| $rootScope.$on('$viewContentLoaded', function (event) { | |
| if (handler.active) { | |
| $log.debug("$viewContentLoaded --- event", arguments); | |
| } | |
| }); | |
| $rootScope.$on('$stateNotFound', function (event, unfoundState, fromState, fromParams) { | |
| if (handler.active) { | |
| $log.debug("$stateNotFound --- event, unfoundState, fromState, fromParams", arguments); | |
| } | |
| }); | |
| return handler; | |
| } | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment