Activity › Forums › Salesforce® Discussions › What is Basic difference between Application Event and Component Event in lightning component?
-
What is Basic difference between Application Event and Component Event in lightning component?
Posted by Hariom Chaudhary on September 12, 2019 at 7:25 AMWhat is Basic difference between Application Event and Component Event in lightning component?
Achintya replied 6 years, 9 months ago 3 Members · 2 Replies -
2 Replies
-
Hi Hariom,
Component events are used to do communication between child and parent. They use bubbling and capture same as used in DOM events. A change in a child component can be communicated to the parent component via component event.
Application events are used to communicate any change in the component to a broader audience. Any component who has registered for this event will get a notified.
Thanks
- [adinserter block='9']
-
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. The component that fires an event can set the event’s data. To set the attribute values, call event.setParam() or event.setParams().
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. To create a custom application event, you need to use the <aura: event> tag in the event resource. You need to define the type=” Application” tag. To use you need to register application event same way as the component event.
To fire the application event you need to use event.setParam();
Events are of the most widely used in lightning component. So when you should use which one is also important.
Log In to reply.