Created
June 26, 2017 17:17
-
-
Save Sunil02kumar/ad6e8f5106b7655a0f7f21d49de97e6e to your computer and use it in GitHub Desktop.
Firing component event from VF Page in lightning
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" description="Event template" > | |
<aura:attribute name="valuePassedFromEvent" 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
<apex:page standardcontroller="Account" sidebar="false"> | |
<apex:includeLightning /> | |
<div id="compContainer" /> | |
<!--Here here skforce in script is my org namespace. if you are not using namespace in your org, | |
then simply use c. like c:VFPageApp, c:VFPageComponent etc--> | |
<script> | |
$Lightning.use("skforce:VFPageApp", function() { | |
$Lightning.createComponent("skforce:VFPageComponent", | |
{PassesValueFromVF:"{!JSENCODE(Account.Name)}"}, | |
"compContainer", | |
function(cmp) { | |
console.log("skforce:VFPageApp loaded successfully in VF page"); | |
//if you register event in component then use below syntax | |
var eve = cmp.getEvent("cmpEvent"); | |
eve.setParams( | |
{ | |
valuePassedFromEvent:"{!JSENCODE(Account.BillingCountry)}" | |
}); | |
console.log("firing event from VF page"); | |
eve.fire(); | |
console.log("event firing from VF page completed"); | |
} | |
); | |
}); | |
</script> | |
</apex:page> |
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 access="GLOBAL" extends="ltng:outApp"> | |
<c:VFPageComponent /> | |
</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 name="valueRecievedFromEvent" type="string"/> | |
<aura:attribute name="PassesValueFromVF" type="string"/> | |
<aura:registerEvent name="cmpEvent" type="c:EventForVFPage"/> | |
<aura:handler name="cmpEvent" event="c:EventForVFPage" action="{!c.eventHandlerFromVF}"/> | |
Account name Passed through component attribute from VF Page: <b>{!v.PassesValueFromVF}</b> | |
<br/> | |
Account billing country Passed from event: <b>{!v.valueRecievedFromEvent}</b> | |
</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
({ | |
eventHandlerFromVF : function(component, event, helper) { | |
console.log("event captured in component controller in eventHandlerFromVF function"); | |
var passedValue=event.getParam("valuePassedFromEvent"); | |
console.log("**passedValue through event:"+passedValue); | |
component.set("v.valueRecievedFromEvent",passedValue); | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment