angularjs - $rootScope.$broadcast vs. $scope.$emit -



angularjs - $rootScope.$broadcast vs. $scope.$emit -

now performance difference between $broadcast , $emit has been eliminated, there reason prefer $scope.$emit $rootscope.$broadcast?

they different, yes.

$emit restricted scope hierarchy (upwards) - may good, if fits design, seems me rather arbitrary restriction.

$rootscope.$broadcast works across choose hear event, more sensible restriction in mind.

am missing something?

edit:

to clarify in response answer, direction of dispatch not issue i'm after. $scope.$emit dispatches event upwards, , $scope.$broadcast - downwards. why not utilize $rootscope.$broadcast reach intended listeners?

$rootscope.$emit lets other $rootscope listeners grab it. when don't want every $scope it. high level communication. think of adults talking each other in room kids can't hear them.

$rootscope.$broadcast method lets pretty much hear it. equivalent of parents yelling dinner ready in house hears it.

$scope.$emit when want $scope , parents , $rootscope hear event. kid whining parents @ home (but not @ grocery store other kids can hear).

$scope.$broadcast $scope , children. kid whispering stuffed animals parents can't hear.

tl;dr (this tl;dr @sp00m reply below)

$emit dispatches event upwards ... $broadcast dispatches event downwards

angularjs angularjs-scope

Comments

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -