AngularJS publisher and subscriber
AngularJS supports the publish and subscribe mechanism to communicate among modules. It uses
$on to implement, publish and subscribe design pattern. Using
$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 ...