I created a lightning component that will house a drag and drop file uploader and handle all of its goings ons.
Then I bring it into my Visualforce page like so:
$Lightning.use('c:DropZoneComponentApp', function(){
$Lightning.createComponent('c:DropZoneComponent', {eventId: currentEvent.taskId}, 'eventDropzone', function(cmp){
console.log('Component Created!', cmp);
console.log(cmp.get('v.fileInfo'));
//console.log(cmp.testingFunction()); <--Doesn't work
});
});
I now want to be able to call functions of the lightning component when a button is pressed on my Visualforce page. just doing cmp.functionName() does not seem to work.
How do you accomplish this? I am OK triggering the AuraEnabled controller methods for the component, or the javascript controller methods.
Best Answer
You can use
aura:method
to invoke lightning controller methods as follows. Store the generated component to a global variable and invoke the aura:method to call your controller action. You can either call lightning controller methods which could, in turn, call the @AuraEnabled Methods or use RemoteActions to call your apex class methods, it really depends on your use case.