Newer Version Available

This content describes an older version of this product. View Latest

Create Custom Application Events

Create a custom application event using the <aura:event> tag in a .evt resource. Events can contain attributes that can be set before the event is fired and read when the event is handled.

Use type="APPLICATION" in the <aura:event> tag for an application event. For example, this c:appEvent application event has one attribute with a name of message.

1<!--c:appEvent-->
2<aura:event type="APPLICATION">
3    <!-- Add aura:attribute tags to define event shape.
4         One sample attribute here. -->
5    <aura:attribute name="message" type="String"/>
6</aura:event>

The component that fires an event can set the event’s data. To set the attribute values, call event.setParam() or event.setParams(). A parameter name set in the event must match the name attribute of an <aura:attribute> in the event. For example, if you fire c:appEvent, you could use:

1event.setParam("message", "event message here");

The component that handles an event can retrieve the event data. To retrieve the attribute in this event, call event.getParam("message") in the handler’s client-side controller.