Hello Shradha,
Basically there are two types of Events as everyone answered -
Let me tell you the basic difference and when to choose what -
COMPONENT EVENT : It only works if one component is in Parent-child relationship with other component.
In Other words- To talk to a parent using the capture and bubbling mechanism, like with DOM events. Usually, one component is interested by the event, like an event aggregator.
Component must reference events by name, much like an aura:id, and retrieve them from its component (hence component.get()) value provider:
var evt = cmp.get("e.myEvent");
You would then declare myEvent on the component as:
<aura:registerEvent name="myEvent" type="namespace:eventName"/>
Declaring events on a component allows other components to call controller methods. You had to declare a handler:
<aura:handler name="myEvent" action="{!c.myEventHandler}"/>
That allowed you to call myEventHandler from another component and respect the interface:
component.get("e.myEvent").fire();
For Example refer this Link : https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/events_component_example.htm
APPLICATION EVENT : This will help you in communication between components which are not necessarily related.
In other words :
To broadcast to other components and not exclusively ancestors. Applications events can talk to many components that can be interested by the event. The broadcast can be boxed to an area of the DOM (everything below a DIV for example).
This is obtained from the global (hence $A.get()) event value provider:
var evt = $A.get("e.myNamespace:myEvent");
For Example Refer this link : https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/events_application_example.htm
Hope this will help.
Thanks
-
This reply was modified 6 years, 1 month ago by Jade.