JavaScript fullCalendar reading plugin 'applyAll' as undefined in gcal.js

I am trying to use the google calendar module of the fullcalendar plugin in JavaScript. When I try to download the Google calendar, the console displays:

Uncaught TypeError: Cannot read property 'applyAll' of undefined 

The error occurs on line 23 gcal.js:

 21| var fc = $.fullCalendar; 22| console.log($.fullCalendar); 23| var applyAll = fc.applyAll; 

The console.log () I added, returns $ .fullCalendar as undefined, and then fc.applyAll also returns undefined. My JS knowledge is not good enough to fully understand what is going on in this file, and I'm not sure what is going wrong.

Here is my html:

 <head> <link rel='stylesheet' href='fullcalendar/fullcalendar.css' /> <script src='fullcalendar/lib/jquery.min.js'></script> <script src='fullcalendar/gcal.js'></script> <script src='fullcalendar/lib/moment.min.js'></script> <script src='fullcalendar/fullcalendar.js'></script> <link href='style.css' rel='stylesheet' /> </head> <body> <div id='calendar'></div> </body> 

My JavaScript:

  $(document).ready(function() { $('#calendar').fullCalendar({ googleCalendarApiKey: 'my-api-key', events: { googleCalendarId: 'my-calendar-id' } }); }); 

And I downloaded the latest version of gcal.js (there seemed to be a problem with the file, and the site provided a link to the latest version).

+5
source share
1 answer

The problem is that you imported library files.

fullcalendar is a jQuery plugin that usually means that it will appear as a property of a jQuery object, for example. $.fullCalendar .

Now the gcal file depends on whether this property exists, so it can access the .applyAll method on it, however you load gcal.js before loading fullcalendar.js .

If you change the order like this, it works without a problem.

 <script src='fullcalendar/lib/jquery.min.js'></script> <script src='fullcalendar/lib/moment.min.js'></script> <script src='fullcalendar/fullcalendar.js'></script> <script src='fullcalendar/gcal.js'></script> 

As a rule, try and place files that, as you know, have no dependencies (they do not rely on another library).

+9
source

All Articles