Skip to content
This repository was archived by the owner on Feb 18, 2022. It is now read-only.

Commit 04db8c7

Browse files
committed
Adapting code to deregister the watcher
1 parent ecbaa92 commit 04db8c7

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

src/js/angular-datepicker.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@
175175
$scope.day = Number($filter('date')(new Date($scope.dateMinLimit), 'dd'));
176176
$scope.year = Number($filter('date')(new Date($scope.dateMinLimit), 'yyyy'));
177177

178-
setDaysInMonth($scope.monthNumber, $scope.year);
178+
setDaysInMonth($scope.monthNumber, $scope.year);
179179
}
180180
, resetToMaxDate = function resetToMaxDate() {
181181

@@ -378,6 +378,11 @@
378378
setInputValue();
379379
}
380380
}
381+
})
382+
, unregisterDateMinLimitWatcher = $scope.$watch('dateMinLimit', function dateMinLimitWatcher(newValue){
383+
if(newValue){
384+
resetToMinDate();
385+
}
381386
});
382387

383388
$scope.nextMonth = function nextMonth() {
@@ -488,13 +493,7 @@
488493
$scope.monthNumber = Number($filter('date')(new Date(selectedMonthNumber + '/01/2000'), 'MM'));
489494
setDaysInMonth($scope.monthNumber, $scope.year);
490495
setInputValue();
491-
};
492-
493-
$scope.$watch('dateMinLimit', function(){
494-
if($scope.dateMinLimit)
495-
resetToMinDate();
496-
})
497-
496+
};
498497

499498
$scope.setNewYear = function setNewYear(year) {
500499

@@ -839,6 +838,7 @@
839838
$scope.$on('$destroy', function unregisterListener() {
840839

841840
unregisterDataSetWatcher();
841+
unRegisterDateMinLimitWatcher();
842842
thisInput.off('focus click focusout blur');
843843
angular.element(theCalendar).off('mouseenter mouseleave focusin');
844844
angular.element($window).off('click focus focusin', onClickOnWindow);

0 commit comments

Comments
 (0)