Joe Hawkins Joe Hawkins - 1 year ago 163
AngularJS Question

UI Router 1.0 state change events not working

I'm migrating my Angular 1.5 application to Angular UI Router 1.0-beta3 to use the component router. I'm listening for state change events on $rootScope but none of the events are fired.


.module('app', [ 'ui.router' ])
.config(function($stateProvider) {
url: '/dashboard',
component: 'dashboardComponent',
resolve: {
enabled: function() { throw new Error('NOT ENABLED'); }
.run(function($rootScope) {
$rootScope.$on('$stateChangeError', function() {
// Never called

Are state change events supported in component routing?

Answer Source

State change events are supported in component routing, but UI Router handles events differently in v1.0.

Try this:


.run(function($transitions) {
    $transitions.onError({}, function() {
        // Works like a charm

See the docs for more info

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download