We need to use myResource.js file with helloWorld() function that we have downloaded into "static resource." We need to call helloWorld() on button clicks and some other events.
I've created simple lightning component trying to implement the above.
afterScriptLoaded is Not needed in our case. I need to call helloWorld() in myResource.js on button click.
helloWorld() --- does Not get called, no errors
This lightning component is used on Community page.
I did see How do I call functions loaded from a Static Resource JavaScript file? and many other posts, but are there any other ways to resolve it besides "attach your utility methods to the global window object(SecureWindow)"? And does it work Only with 'afterScriptLoaded' ?
Please see my code below and let me know what is wrong. Many thanks
myTest.cmp
<aura:component implements="forceCommunity:availableForAllPageTypes" access="global">
<ltng:require scripts="{!$Resource.myResource }"/>
<lightning:button label="Test1" onclick="{! c.callJsFunction }" />
</aura:component>
Controller myTest.js
({
callJsFunction: function(component, event, helper) {
helloWorld(); // does Not get called
//alert("Inside callJsFunction"); // works
}
})