Question

To un-subscribed from $broadcast in $on, one can do

var cleanUp = $rootScope.$on('myBroadcast', function(){ ... });
cleanUp();

Is there a way to re-subscribe once you have called cleanUp()?

Was it helpful?

Solution

function foo () {
  return $rootScope.$on('myBroadcast', function(){ ... });
}
var cleanup = foo(); // listen

// somewhere down the road
cleanup(); // unlisten

// somewhere down the road
foo(); // listen again
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top