Created
October 9, 2016 15:43
-
-
Save kiran-machhewar/45917805e21d1d451e55bca35719aa88 to your computer and use it in GitHub Desktop.
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
<apex:page > | |
<apex:includeLightning /> | |
<div id="lightning" /> | |
<button type="button" onclick="callLightningEvent();">Call Lightning Code From VF</button> | |
<script> | |
window.onload = function() { | |
$Lightning.use("c:LightningOutExampleApp", function() { | |
var comapp=$Lightning.createComponent("c:LightningOutExample", | |
{}, | |
"lightning", | |
function(component) { | |
console.log('Lightning out -->Component has been loaded.'); | |
$A.eventService.addHandler({ "event": "c:lightningAppExternalEvent", "handler" : myFunctionFromVisualforce }); | |
}); | |
}); | |
} | |
function callLightningEvent(){ | |
var lightningEvent = $A.get("e.c:lightningAppEvent"); | |
lightningEvent.setParams({'data':{'TestDataKey':'TestDataValue'}}); | |
lightningEvent.fire(); | |
} | |
function myFunctionFromVisualforce (event){ | |
console.log('This message is from visualforce function'); | |
console.log('Data which is coming from lightning component',event.getParam('data')); | |
debugger; | |
} | |
</script> | |
</apex:page> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello sir,
when i am calling callLightningEvent function. its giving below error plz look it, sir. plz guide me where i m doing wrong sir. waiting for ur reply sir. thnx in advance.
aura_prod.js:853 Uncaught TypeError: Cannot read property 'setParams' of undefined
throws at https://practice-org-dev-ed--c.ap4.visual.force.com/apex/LightningOutExampleVF?core.apexpages.request.devconsole=1:26:28 TypeError: Cannot read property 'setParams' of undefined
at callLightningEvent (LightningOutExampleVF?core.apexpages.request.devconsole=1:26)
at HTMLButtonElement.onclick (LightningOutExampleVF?core.apexpages.request.devconsole=1:9)