Skip to content
This repository was archived by the owner on May 29, 2019. It is now read-only.

Commit 74a8be4

Browse files
committed
fix(datepicker): commit safe apply on destruction
- Ensure we are not in a $digest before executing an $apply on scope destruction to avoid potential error Closes #4079 Fixes #4076
1 parent ca9196f commit 74a8be4

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/datepicker/datepicker.js

+7-5
Original file line numberDiff line numberDiff line change
@@ -474,8 +474,8 @@ angular.module('ui.bootstrap.datepicker', ['ui.bootstrap.dateparser', 'ui.bootst
474474
showButtonBar: true
475475
})
476476

477-
.directive('datepickerPopup', ['$compile', '$parse', '$document', '$position', 'dateFilter', 'dateParser', 'datepickerPopupConfig', '$timeout',
478-
function ($compile, $parse, $document, $position, dateFilter, dateParser, datepickerPopupConfig, $timeout) {
477+
.directive('datepickerPopup', ['$compile', '$parse', '$document', '$rootScope', '$position', 'dateFilter', 'dateParser', 'datepickerPopupConfig', '$timeout',
478+
function ($compile, $parse, $document, $rootScope, $position, dateFilter, dateParser, datepickerPopupConfig, $timeout) {
479479
return {
480480
restrict: 'EA',
481481
require: 'ngModel',
@@ -749,9 +749,11 @@ function ($compile, $parse, $document, $position, dateFilter, dateParser, datepi
749749

750750
scope.$on('$destroy', function() {
751751
if (scope.isOpen === true) {
752-
scope.$apply(function() {
753-
scope.isOpen = false;
754-
});
752+
if (!$rootScope.$$phase) {
753+
scope.$apply(function() {
754+
scope.isOpen = false;
755+
});
756+
}
755757
}
756758

757759
$popup.remove();

0 commit comments

Comments
 (0)