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>

1 Answer 1

6

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.

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .