Angularjs Examples

AJS Examples


AngularJS $scope.$on() Function

The AngularJS $on method is used to listens dispatched events of a given type. The $on method catches the event dispatched by $broadcast and $emit methods.

Syntax

  • In the $on method name is the event name. This watchExpression is called on every $digest() and returns the value that is being watched.
  • In the $watch method listener is a function that is called when the value of the $scope property are not equal to previous value. If the watchExpression is equal to previous value then listener will not be called.
  • In the $watch method objectEquality is a boolean type and used for object equality using angular.equals instead of comparing for reference equality.

AngularJS $scope.$on() Function Example