Tried to find some basic information for AngularJS $rootScope.$broadcast
, But the AngularJS documentation doesn't help much. In easy words why do we use this?
Also, inside John Papa's Hot Towel template there is a custom function in the common module named $broadcast
:
function $broadcast() {
return $rootScope.$broadcast.apply($rootScope, arguments);
}
I did not understand what this is doing. So here are couple of basic questions:
1) What does $rootScope.$broadcast
do?
2) What is the difference between $rootScope.$broadcast
and $rootScope.$broadcast.apply
?
$rootScope.$broadcast.apply()
is used because if you want to pass the specialarguments
object to another function, you need to useapply()
(as opposed tocall()
). In addition to @Blackhole's link to the MDN page on apply, you might also check out the entry onarguments
. – Maidel