You need to sign in to do that
Don't have an account?
KenBarlow
How to access javascript variable in static resources for lightning component js helper?
I've got a lightning component that I'm working on and I can see that that javascript file is loading properly (in chrome developer console) from static resources as shown below.
The problem is that I'm attempting to access a variable within that javascript file through a lightning component helper.js file.
Lightning Component - Home.cmp
- Loads the static resource js file.
Lightning Component JavaScript Controller File - HomeController.js
- Calls a function on the helper to then access and use the variable.
Lightning Component JavaScript Helper File - HomeHelper.js
The question is, how can I access that variable from the static resource all the way down inside of the HomeHelper.js file?
Thanks.
<ltng:require scripts="{!join(',' , $Resource.Main_Assets + '/scripts/embed.min.js', )}" afterScriptsLoaded="{!c.doInit}" />
The problem is that I'm attempting to access a variable within that javascript file through a lightning component helper.js file.
Lightning Component - Home.cmp
- Loads the static resource js file.
Lightning Component JavaScript Controller File - HomeController.js
- Calls a function on the helper to then access and use the variable.
doInit: function(cmp, event, helper){ helper.setupItem(); }
Lightning Component JavaScript Helper File - HomeHelper.js
setupItem: function() { // This is where I'm trying to access the value from the static resource, but it's not letting me access it. console.log(variableNameFromStaticResourceJSFile); );
The question is, how can I access that variable from the static resource all the way down inside of the HomeHelper.js file?
Thanks.
I guess you are wrongly calling variable do something like this:
{!URLFOR($Resource.resourceName, 'img/imageName.jpg')}
This is example of setting url with the value of resourceName with path as img/
<apex:image url="{!URLFOR($Resource.resourceName, 'img/imageName.jpg')}" width="50" height="50"/>
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks,
Ajay Dubedi
Greetings to you!
It should be like this : -
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks and Regards,
Deepali Kulshrestha.