Skip to content

Instantly share code, notes, and snippets.

@pozil
Last active March 5, 2022 15:01
  • Star 8 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save pozil/36b93995d9d84463b46060d161129198 to your computer and use it in GitHub Desktop.
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