O'Reilly logo

Responsive Web Design with AngularJS by Sandeep Kumar Patel

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

AngularJS publisher and subscriber

AngularJS supports the publish and subscribe mechanism to communicate among modules. It uses $emit, $broadcast, and $on to implement, publish and subscribe design pattern. Using $emit and $broadcast, a message can be published inside the AngularJS application. Using the $on method, a published message can be subscribed.

Publishing a message using $emit

When a message is published using $emit, it starts propagating from the current scope to the upper level scope and continues up to the application scope, which is $rootScope. The following code shows the syntax of the $emit method to publish a message:

$scope.$emit("<message>",<argument>);
$rootScope.$emit("<message>",<argument>);

In the previous code, you can see ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required