Now that the performance difference between $broadcast
and $emit
has been eliminated, is there any reason to prefer $scope.$emit
to $rootScope.$broadcast
?
They are different, yes.
$emit
is restricted to the scope hierarchy (upwards) - this may be good, if it fits your design, but it seems to me a rather arbitrary restriction.
$rootScope.$broadcast
works across all that choose to listen to the event, which is a more sensible restriction in my mind.
Am I missing something?
EDIT:
To clarify in response to an answer, the direction of the dispatch is not the issue I'm after. $scope.$emit
dispatches the event upwards, and $scope.$broadcast
- downwards. But why not always use $rootScope.$broadcast
to reach all the intended listeners?
Question&Answers:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…