Ligthning - Passing data up and around the component hierarchy via an application component
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<aura:event type="APPLICATION"> | |
<aura:attribute name="param" type="String"/> | |
</aura:event> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<aura:component> | |
<aura:handler event="c:applicationEvent" action="{!c.handleMyApplicationEvent}"/> | |
</aura:component> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
({ | |
handleMyApplicationEvent : function(component, event, helper) { | |
var value = event.getParam("param"); | |
alert("Received application event with param = "+ value); | |
} | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<aura:component> | |
<aura:registerEvent name="myApplicationEvent" type="c:applicationEvent"/> | |
<lightning:button label="Fire application event" onclick="{! c.fireMyApplicationEvent }" /> | |
</aura:component> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
({ | |
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