What is the difference between $rootScope.$emit & $rootScope.$broadcast
Quick Recap of $scope
$scope.$emit
fires an event up to the parent $scopes
.
$scope.$broadcast
fires an event down the $scope
.
Using $scope.$on
we can listen for these events.
$rootScope – The Problem Statement
$rootScope
has no $parent
, hence using an $emit
for most obvious reasons seems pointless.
However, a $rootScope.$emit(ted) event can only
be caught by
$rootScope.$on
listeners and not by $scope.on listeners.
On the other hand, $rootScope.$broadcast
will notify all $rootScope.$on
and $scope.$on
listeners
Sponsor : Text Messaging API | Frontend Engineer Jobs in Los Angeles, CA