Understanding $rootScope event with $broadcast and $on


Please refer my previous article for better explanation. Now directly i am moving to the execution of code.

Like how we used $scope just replace with $rootScope. Thats it. For reference here is the code..


<script src=”angular.min.js”></script>
<script src=”script.js”></script>
<div ng-app=”sathya”>
<div ng-controller=”ParentCtrl”>
<button ng-click=”go()”>Button </button>
<div ng-controller=”SiblingCtrl”>


var app = angular.module(‘sathya’,[]);

function ParentCtrl ($scope,$rootScope) {
$scope.go = function() {
$rootScope.$broadcast(‘Sathyalog’,”How are you”)


function SiblingCtrl ($scope,$rootScope) {
$rootScope.$on(‘Sathyalog’, function (event, data) {
alert(“Iam executed”);


One thought on “Understanding $rootScope event with $broadcast and $on

  1. Pingback: Understanding Angular’s $scope event system with $broadcast and $on | Sathya's Log

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s