ServiceNow AngularJS: $broadcast vs $emit

ServiceNow AngularJS: $broadcast vs $emit

$broadcast: Parent to Child

Set Event:

$timeout(function() {
$rootScope.$broadcast('userCountry', value);
}, 500);

Get Event:

$scope.$on('userCountry', function(event, userCountry) {
console.log(userCountry + '----userCountry');
c.searchLoc = userCountry;
------------------------------------------------------------------------------

$emit: Child to Parent

Set Event:

function($rootScope, $scope) {
var c = this;
c.selectNote = function(number) {
$rootScope.noteID = number;
$rootScope.$emit('selectNote', number);
}
}

Get Event:

function($rootScope, $scope) {
var c = this;
$rootScope.$on('selectNote', function(event, data) {
return $rootScope.noteID;
});
}

References:
https://github.com/towrain/SNOW-data-between-widgets
https://youtu.be/LooT596ZhtQ


Demo: