Difference between Application Events and Component Events in Lightning #Salesforce

August 3, 2018

Component Events

A component event is fired from an instance of a component. A component event can be handled by the component that fired the event or by a component in the containment hierarchy that receives the event. The component that fires an event is known as the source component.

1

The component that fires an event can set the event’s data. To set the attribute values, call event.setParam() or event.setParams().

Fire a component Event

In terms of firing an event you need to register that component event in your component and then you can fire the same. it looks something like below

2

A component can handle its own event by using the <aura:handler> tag in its markup. The name attributes in <aura:registerEvent> and <aura:handler> must match, since each event is defined by its name.

 

3

 

Application Events

Application event in simple words can be used in multiple components and component that has the handler for the event will be notified.

4

 

To create a custom application event, you need to use the <aura:event> tag in the event resource. You need to define type=”Application” tag. To use you need to register application event same way as component event

 

5

To fire the application event you need to use event.setParam();

6

 
Events are of the most widely used in lightning component. So when you should use which one is also important.

Thanks