From b5621dfd75da328b835ef15423cb1524ab9af6f1 Mon Sep 17 00:00:00 2001 From: Matt Lewis Date: Wed, 10 Feb 2016 09:13:03 +0000 Subject: [PATCH] fix: start watchers after templates have been loaded --- src/directives/mwlCalendar.js | 41 ++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/src/directives/mwlCalendar.js b/src/directives/mwlCalendar.js index 8d28a9a9..89679d3c 100644 --- a/src/directives/mwlCalendar.js +++ b/src/directives/mwlCalendar.js @@ -87,28 +87,29 @@ angular } } - var eventsWatched = false; - - //Refresh the calendar when any of these variables change. - $scope.$watchGroup([ - 'vm.viewDate', - 'vm.view', - 'vm.cellIsOpen', - function() { - return moment.locale() + $locale.id; //Auto update the calendar when the locale changes - } - ], function() { - if (!eventsWatched) { - eventsWatched = true; - //need to deep watch events hence why it isn't included in the watch group - $scope.$watch('vm.events', refreshCalendar, true); //this will call refreshCalendar when the watcher starts (i.e. now) - } else { - refreshCalendar(); - } - }); - calendarHelper.loadTemplates().then(function() { vm.templatesLoaded = true; + + var eventsWatched = false; + + //Refresh the calendar when any of these variables change. + $scope.$watchGroup([ + 'vm.viewDate', + 'vm.view', + 'vm.cellIsOpen', + function() { + return moment.locale() + $locale.id; //Auto update the calendar when the locale changes + } + ], function() { + if (!eventsWatched) { + eventsWatched = true; + //need to deep watch events hence why it isn't included in the watch group + $scope.$watch('vm.events', refreshCalendar, true); //this will call refreshCalendar when the watcher starts (i.e. now) + } else { + refreshCalendar(); + } + }); + }).catch(function(err) { $log.error('Could not load all calendar templates', err); });