Skip to content

Instantly share code, notes, and snippets.

@kiran-machhewar
Created October 9, 2016 15:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kiran-machhewar/45917805e21d1d451e55bca35719aa88 to your computer and use it in GitHub Desktop.
Save kiran-machhewar/45917805e21d1d451e55bca35719aa88 to your computer and use it in GitHub Desktop.
<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>
@AmitBhati07
Copy link

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment