Skip to content

Instantly share code, notes, and snippets.

Last active June 27, 2021 06:52
  • Star 10 You must be signed in to star a gist
  • Fork 6 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save pozil/70e101ae3e22dc4330474ea2ffb040bb to your computer and use it in GitHub Desktop.
Lightning - Passing data up the component hierarchy via a component event
<aura:event type="COMPONENT">
<aura:attribute name="param" type="String"/>
<aura:handler name="myComponentEvent" event="c:componentEvent" action="{!c.handleMyComponentEvent}"/>
handleMyComponentEvent : function(component, event, helper) {
var value = event.getParam("param");
alert("Received component event with param = "+ value);
<aura:registerEvent name="myComponentEvent" type="c:componentEvent"/>
<lightning:button label="Fire component event" onclick="{! c.fireMyComponentEvent }" />
fireMyComponentEvent : function(component, event, helper) {
var myEvent = component.getEvent("myComponentEvent");
myEvent.setParams({"param": "It works!"});;
Copy link

The example is not working.
A missing piece of code is:
<c:componentEventSender myComponentEvent="{!c.handleMyComponentEvent}" />

Copy link

@khladkyi It should work. The event handler is already specified in componentEventReceiver.cmp at line #2.

Copy link

AjManoj commented Jan 21, 2019

for some reason it doesn't in some situations even i tried,not sure what is the exact cause

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment