-
-
Save karkranikhil/e47a4713b0c3884255b23e3232ec9181 to your computer and use it in GitHub Desktop.
Lightning - Passing data up the component hierarchy via a component event
This file contains hidden or 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="COMPONENT"> | |
| <aura:attribute name="param" type="String"/> | |
| </aura:event> |
This file contains hidden or 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 name="myComponentEvent" event="c:componentEvent" action="{!c.handleMyComponentEvent}"/> | |
| <c:componentEventSender/> | |
| </aura:component> |
This file contains hidden or 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
| ({ | |
| handleMyComponentEvent : function(component, event, helper) { | |
| var value = event.getParam("param"); | |
| alert("Received component event with param = "+ value); | |
| } | |
| }) |
This file contains hidden or 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="myComponentEvent" type="c:componentEvent"/> | |
| <lightning:button label="Fire component event" onclick="{! c.fireMyComponentEvent }" /> | |
| </aura:component> |
This file contains hidden or 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
| ({ | |
| 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