Ligthning - Passing data up and around the component hierarchy via an application component
<aura:event type="APPLICATION"> | |
<aura:attribute name="param" type="String"/> | |
</aura:event> |
<aura:component> | |
<aura:handler event="c:applicationEvent" action="{!c.handleMyApplicationEvent}"/> | |
</aura:component> |
({ | |
handleMyApplicationEvent : function(component, event, helper) { | |
var value = event.getParam("param"); | |
alert("Received application event with param = "+ value); | |
} | |
}) |
<aura:component> | |
<aura:registerEvent name="myApplicationEvent" type="c:applicationEvent"/> | |
<lightning:button label="Fire application event" onclick="{! c.fireMyApplicationEvent }" /> | |
</aura:component> |
({ | |
fireMyApplicationEvent : function(component, event, helper) { | |
var myEvent = $A.get("e.c:applicationEvent"); | |
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