要从$broadcast
中的$on
取消订阅,可以执行
var cleanUp = $rootScope.$on('myBroadcast', function(){ ... });
cleanUp();
调用cleanUp()
后,有没有办法重新订阅?
答案 0 :(得分:2)
function foo () {
return $rootScope.$on('myBroadcast', function(){ ... });
}
var cleanup = foo(); // listen
// somewhere down the road
cleanup(); // unlisten
// somewhere down the road
foo(); // listen again