Last active
August 19, 2018 01:22
-
-
Save Sunil02kumar/80b04c428e59da2caca4f740a5fb7ca9 to your computer and use it in GitHub Desktop.
Application Events : Way to Communicate Between Different Lightning Components
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:application extends="force:slds"> | |
<c:SK_FirstComponent/> | |
<c:SK_SecondComponent/> | |
</aura:application> |
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:attribute type="String" name="ltngUserInput"/> | |
<div style="background-color:#E6E6FA;border-style: solid;margin:5%;padding:2%;"> | |
<b>First Component</b> | |
<br/> | |
<lightning:input value="{!v.ltngUserInput}" label="Enter some value" | |
required="true" placeholder="Enter some value"/> | |
<lightning:button variant="brand" label="Send entered value to next component" onclick="{!c.handleClick }" /> | |
</div> | |
</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
({ | |
handleClick:function(component, event, helper) { | |
console.log("handle click get called."); | |
var appEvent = $A.get("e.c:SK_MessengerEvent"); | |
appEvent.setParams({"msg":component.get("v.ltngUserInput")}); | |
appEvent.fire(); | |
} | |
}) |
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="APPLICATION" description="Event template" > | |
<aura:attribute name="msg" type="String" access="GLOBAL"/> | |
</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:attribute name="recMsg" type="String" /> | |
<aura:handler action="{!c.handleNotification}" event="c:SK_MessengerEvent" /> | |
<div style="background-color:grey;border-style: solid;margin:5%;padding:2%;"> | |
<b>Second component</b> | |
<br /> | |
Passed value from First componet--<b>{!v.recMsg}</b> | |
</div> | |
</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
({ | |
handleNotification:function(component, event, helper) { | |
console.log("Event Handled"); | |
var sentMessage= event.getParam("msg"); | |
console.log('******sentMessage by app event:'+sentMessage); | |
component.set("v.recMsg",sentMessage); | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment