Skip to content

Instantly share code, notes, and snippets.

@nithesh1992
Forked from pozil/componentEvent.evt
Created May 10, 2017 19:34
Show Gist options
  • Save nithesh1992/0285c12fe9fd92eae41b20d310348fba to your computer and use it in GitHub Desktop.
Save nithesh1992/0285c12fe9fd92eae41b20d310348fba 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();
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment