3

I've seen the thread in documentation here on loading static resources using ltng:require, but I don't quite get the formatting via the example. I'm looking for some assistance to make sure what i'm doing is correct, because i'm getting an error while attempting to load these resources in the browser.

These are my files in static resources

  • Resource Name: MomentJS | Filename: /moment.min.js
  • Resource Name: FullCalendarCSS | Filename: /fullcalendar.css
  • Resource Name: FullCalendarJS | Filename: /fullcalendar.js
  • Resource Name: jQuery | Filename: /jquery.min.js

This is the code I have to attach these files to my lightning component

fullCalendar.cmp

<aura:component controller="FullCalendarController" implements="force:appHostable">
  <ltng:require styles="{!$Resource.FullCalendarCSS + '/fullcalendar.css'}"
    scripts="{!join(',', 
    $Resource.FullCalendarJS + '/fullcalendar.js', 
    $Resource.jQuery + '/jquery.min.js',
    $Resource.MomentJS + '/moment.min.js')}"
    afterScriptsLoaded="{!c.scriptsLoaded}"/>
  <aura:attribute name="events" type="Events[]" />
  <div id="calendar"></div>
</aura:component>
5

You don't have to precise the name of the file if your static resource is only one file. You just have to do:

<aura:component controller="FullCalendarController" implements="force:appHostable">
  <ltng:require styles="{!$Resource.FullCalendarCSS}"
    scripts="{!join(',', 
    $Resource.FullCalendarJS, 
    $Resource.jQuery,
    $Resource.MomentJS)}"
    afterScriptsLoaded="{!c.scriptsLoaded}"/>
  <aura:attribute name="events" type="Events[]" />
  <div id="calendar"></div>
</aura:component>

Whereas, for example, if your static resource is a zip file containing multiple files, you will have to precise the name of the file you want after having loaded the resource.

| improve this answer | |
  • Ahhhhh, ok. The docs are quirky on that. Thanks so much! – csakon Jan 12 '17 at 17:11
  • You're welcome. You're right the documentation is not clear about that. – Martin Lezer Jan 13 '17 at 6:55
  • I've asked our doc writer to add some clarification to the docs. Thank you for bringing this to our attention. – Doug Chasman Jan 17 '17 at 12:55
  • Thank you ! That's really nice to take the time to ask the doc writer to improve this. – Martin Lezer Jan 17 '17 at 13:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.