Skip to content
This repository has been archived by the owner on Jun 19, 2018. It is now read-only.

Commit

Permalink
fix: start watchers after templates have been loaded
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt Lewis committed Feb 10, 2016
1 parent 30da212 commit b5621df
Showing 1 changed file with 21 additions and 20 deletions.
41 changes: 21 additions & 20 deletions src/directives/mwlCalendar.js
Expand Up @@ -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);
});
Expand Down

0 comments on commit b5621df

Please sign in to comment.