function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Shubham Sehgal 2Shubham Sehgal 2 

Loading Javascript using <ltng : require>

Hi All,

I am new Salesforce Lightning experience. I am trying to call an external JavaScript by loading it as a Static resource and calling it in my Lightning application using the following syntax but I am unable to get it work.

<aura:application >
       <ltng:require scripts="{!$Resource.SDFCTestJS}" afterScriptsLoaded="{!c.afterScriptsLoaded}"/>
</aura:application>

Please suggest how can I get it work.

P.S : I read a solution that we can load Javascript by creating a Helper class and call it from our Component. Can anyone suggest a way so that I don't need to create helper everytime I call a component as I am going to have many; a way that I can include the JS directly from the above.

Thanks in advance.

Warm Regards,
Shubham
SFDC
 
hitesh90hitesh90
Hello Shubham,

Try to use normal script tag instead of this.
<script src="{!$Resource.SDFCTestJS}" />
Thank You,
Hitesh Patel
Email :- hiteshpatel.aspl@gmail.com
http://mrjavascript.blogspot.in/
Jasveer SinghJasveer Singh
Hi  
   Shubham Sehgal 


use this code your problem is solve out

<ltng:require scripts="/resource/jq/"/>

where jq is the name of static resource upload in org.

if this is help full please mark the best

Thanks & Regards
Jasveer Singh
Jasveer SinghJasveer Singh
User-added image
Shubham Sehgal 2Shubham Sehgal 2
Hi,

Thank youo for your response.

I tried using your code. Still not working. No error this time but nothing appears on the page.

Please suggest.

Thanks
Jasveer SinghJasveer Singh
please follow this link i already post this type of answer

https://developer.salesforce.com/forums/ForumsMain?id=906F0000000kFDHIA2
Jasveer SinghJasveer Singh
if your problem is solved out please you tell me

Thanks & Regards
Jasveer Singh
Rahul Kumar 151Rahul Kumar 151
<aura:application >
       <ltng:require scripts="/resource/jq/" afterScriptsLoaded="{!c.afterScriptsLoaded}"/>
</aura:application>