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()?

有帮助吗?

解决方案

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

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

// somewhere down the road
foo(); // listen again
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top