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 function that prevents default behavior in a browser event but only executes your own custom code.
■ defaultPrevented: A Boolean that is true
if event.preventDefault()
has been called.