Handling Custom Events with a Listener

To handle an event that is emitted or broadcasted, you use the $on() method. The $on() method uses the following syntax, where name is the name of the event to listen for:

scope.$on(name, listener)

The listener parameter is a function that accepts the event as the first parameter and any arguments passed by the $emit() or $broadcast() method as subsequent parameters. The event object has the following properties:

targetScope: The scope from which $emit() or $broadcast() was called.

currentScope: The scope that is currently handling the event.

name: The name of the event.

stopPropagation(): A function that stops the event from being propagated up or down the scope hierarchy.

preventDefault(): A ...

Get Learning AngularJS now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.