2

I want to use $rootScope.$broadcast() inside onExit when state changes.

But for this, I need to inject $rootScope in the .config(), which is not possible in angular

 onExit: function () {
                //onExit is executed when we leave that state and go to another
                $rootScope.$broadcast('broadCastCloseModalStr');
            }

Can someone help me to achieve it?

Varun Sukheja
  • 6,170
  • 5
  • 51
  • 93

1 Answers1

0

Use the $injector to inject the $rootScope into the onExit, like so

onExit: function($injector) {
    var rootScope = $injector.get('$rootScope');
    console.log("onExit: ", rootScope);
}

However, this should also work

onExit: function($rootScope) {
    console.log("$rootScope: ", $rootScope)
}

Here is a working plunk

svarog
  • 9,477
  • 4
  • 61
  • 77