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:


In the previous code, you can see ...

Get Responsive Web Design with AngularJS now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.