addEventHandler()

Dynamically adds an event handler for a component or application event.

addEventHandler(String event, function handler, String phase, Boolean includeFacets)

event: Type: String. The name of the event to handle. For a component event, set this argument to match the name attribute of the aura:registerEvent tag. For an application event, set this argument to match the event descriptor, namespace:eventName.

handler: Type: function. The handler for the event. There are two format options for this argument.

  • To use a controller action, use the format: cmp.getReference("c.actionName").
  • To use an anonymous function, use the format: function(auraEvent) { // handling logic here }

phase: Type: String. Optional. The event bubbling phase for which to add the handler. The default value is "bubble".

includeFacets: Type: Boolean. If true, attempts to catch events generated by components transcluded by facets; for example v.body.

See Also