# `$on` ( type in module `ng` )

## Description

Listens on events of a given type. See `$emit` for discussion of event life cycle.

The event listener function format is: `function(event, args...)` . The `event` object passed into the listener has the following attributes:

- `targetScope` - `{Scope}` : the scope on which the event was `$emit` -ed or `$broadcast` -ed.
- `currentScope` - `{Scope}` : the current scope which is handling the event.
- `name` - `{string}` : Name of the event.
- `stopPropagation` - `{function=}` : calling `stopPropagation` function will cancel further event propagation (available only for events that were `$emit` -ed).
- `preventDefault` - `{function}` : calling `preventDefault` sets `defaultPrevented` flag to true.
- `defaultPrevented` - `{boolean}` : true if `preventDefault` was called.

## Usage

    Scope#$on(name, listener);

### Parameters

- `name – {string} –`

  Event name to listen on.

- `listener – {function(event, args...)} –`

  Function to call when the event is emitted.

### Returns

`{function()}` –

Returns a deregistration function for this listener.