How to debug AngularJs 1.5 in browser console

Sometimes it’s useful to run service, controller function or view some scope directly in console. Here are several examples how to get access to them.

Service

angular.element($('[ng-app=*]')).injector().get('YourService')

Controller

angular.element('div[ui-view]:eq(1)').controller()
angular.element('#controller_id').controller()

Scope

angular.element('#controller_id').scope()

Routes

Also if there are some problems with ui-router, it’s possible to log the errors.

.run(function($rootScope) {
   $rootScope.$on("$stateChangeError", console.log.bind(console));
});
comments powered by Disqus