Lightning Application Events


In this blog post, I am going to explain how to use the 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.But its good practice to use the component events whenever possible instead of application events.Create an application event contains there steps

Step 1: Create an Application event
Create a new application event with below code as shown below. appEvent.evt

Step 2: 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=”</aura:appEvent” but the value isn’t used anywhere.

Step 3 : Fire an Event
Use $A.get(“e.myNamespace:myAppEvent”) in JavaScript to get an instance of the myAppEvent event in the myNamespace namespace.

Put All together

Now lets put all together to understand the application events.Here below is the component which will trigger the application events.




AppHandler is component that will handle the event notification which is fired from the AppNotifer component and handle them