Component Events vs Application Events

Component Events:

  • Component Events can be handled by same component or a component that instantiates or contains the component.
  • The component events can only be registered in child component and handled by parent component.
  • We use attribute type="COMPONENT" in the aura:event tag for an component event.
  • While handling component events, we need to specify name attribute in aura:handler. The name attribute in aura:handler must match the name attribute in the aura:registerEvent tag in the Child Component that fires the event.
  • We use cmp.getEvent("evtName") in JavaScript to get an instance of the Component type event.

Application Events:

  • Application Events are handled by any component have handler defined for event.These events are essentially a traditional publish-subscribe model.
  • Application event can be used through out the application.
  • We use attribute type="APPLICATION" in the aura:event tag for an application event.
  • While handling application events, no need to specify name attribute in aura:handler.
  • We use $A.get("e.myNamespace:myAppEvent") in JavaScript to get an instance of the Application type event.