Fire Application Events

Application events follow a traditional publish-subscribe model. An application event is fired from an instance of a component. All components that provide a handler for the event are notified.

Register an Event

A component registers that it may fire an application event by using <aura:registerEvent> in its markup. The name attribute is required but not used for application events. The name attribute is only relevant for component events. This example uses name="appEvent" but the value isn’t used anywhere.

<aura:registerEvent name="appEvent" type="c:appEvent"/>

Fire an Event

Use $A.get("e.myNamespace:myAppEvent") in JavaScript to get an instance of the myAppEvent event in the myNamespace namespace.

Note

Note

The syntax to get an instance of an application event is different than the syntax to get a component event, which is cmp.getEvent("evtName").

Use fire() to fire the event.

var appEvent = $A.get("e.c:appEvent");
// Optional: set some data for the event (also known as event shape)
// A parameter’s name must match the name attribute
// of one of the event’s <aura:attribute> tags
//appEvent.setParams({ "myParam" : myValue });
appEvent.fire();

Events Fired on App Rendering

Several events are fired when an app is rendering. All init events are fired to indicate the component or app has been initialized. If a component is contained in another component or app, the inner component is initialized first.

If a server call is made during rendering, aura:waiting is fired. When the framework receives a server response, aura:doneWaiting is fired.

Finally, aura:doneRendering is fired when all rendering has been completed.

Note

Note

We don't recommend using the legacy aura:waiting, aura:doneWaiting, and aura:doneRendering application events except as a last resort. The aura:waiting and aura:doneWaiting application events are fired for every batched server request, even for requests from other components in your app. Unless your component is running in complete isolation in a standalone app and not included in Lightning Experience or Salesforce1, you probably don’t want to handle these application events. The container app may fire server-side actions and trigger your event handlers multiple times.

For more information, see Events Fired During the Rendering Lifecycle.