I want to load a function from external script and then use it in the component controller:
example of a function that i tried to call from the component controller (from the Init method specifically)
function myFunction() {
log.console('Hiiii');
}
I loaded the script like that:
<ltng:require scripts="{!$Resource.DataArrays}"
afterScriptsLoaded="{!c.doInit}" />
then i tried simply to call it from the Init method:
doInit : function(cmp){
myFunction();
}
It does not work, i got an error like this one:
Uncaught Action failed: c:realEstateFilterComponent$controller$doInit [myFunction is not defined]
Do you know to make it work ?
window.myFunction();inside the doInit method?window.myFunction = function (){..}then try as mentioned in my first comment..it will work. I just tried on my end.<aura:handler name="init" value="{!this}" action="{!c.doInit}" />If yes, then resource is not loaded by then.