Skip to content

Instantly share code, notes, and snippets.

@pozil
Last active June 27, 2021 06:52
Show Gist options
  • Save pozil/70e101ae3e22dc4330474ea2ffb040bb to your computer and use it in GitHub Desktop.
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:event>
<aura:component>
<aura:handler name="myComponentEvent" event="c:componentEvent" action="{!c.handleMyComponentEvent}"/>
<c:componentEventSender/>
</aura:component>
({
handleMyComponentEvent : function(component, event, helper) {
var value = event.getParam("param");
alert("Received component event with param = "+ value);
}
})
<aura:component>
<aura:registerEvent name="myComponentEvent" type="c:componentEvent"/>
<lightning:button label="Fire component event" onclick="{! c.fireMyComponentEvent }" />
</aura:component>
({
fireMyComponentEvent : function(component, event, helper) {
var myEvent = component.getEvent("myComponentEvent");
myEvent.setParams({"param": "It works!"});
myEvent.fire();
}
})
@AjManoj
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