Understanding $emit, $broadcast and $on in AngularJS

Sometimes we need to send data from one controller to another. There are services provided by AngularJS for communication(event-based) between the controllers. $on, $emit, $broadcast are the services for the communication between the controllers.

$on :- $on is used to catch the event dispatched by $broadcast and $emit. Basically it’s a method of scope and listens on events of a given type.

$broadcast : — $broadcast is the service that dispatches an event downwards to the child scopes. The life cycle of the event starts at the scope where the $broadcast is called. For example :-

  1. app.controller(“Eg1ctrl”, function ($scope) {
  2. $scope.$broadcast(‘eventName’, { Tips: tip });
  3. });

Here is not the end…

See ful blog about Understanding $emit, $broadcast and $on in AngularJS visit Findnerd.

Also visit Findnerd for such more interesting articles related to Javascript, Android, AngularJS etc.