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

Commit

Permalink
fix(datepicker): commit safe apply on destruction
Browse files Browse the repository at this point in the history
- Ensure we are not in a $digest before executing an $apply on scope destruction to avoid potential error

Closes #4079
Fixes #4076
  • Loading branch information
wesleycho committed Aug 2, 2015
1 parent ca9196f commit 74a8be4
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/datepicker/datepicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -474,8 +474,8 @@ angular.module('ui.bootstrap.datepicker', ['ui.bootstrap.dateparser', 'ui.bootst
showButtonBar: true
})

.directive('datepickerPopup', ['$compile', '$parse', '$document', '$position', 'dateFilter', 'dateParser', 'datepickerPopupConfig', '$timeout',
function ($compile, $parse, $document, $position, dateFilter, dateParser, datepickerPopupConfig, $timeout) {
.directive('datepickerPopup', ['$compile', '$parse', '$document', '$rootScope', '$position', 'dateFilter', 'dateParser', 'datepickerPopupConfig', '$timeout',
function ($compile, $parse, $document, $rootScope, $position, dateFilter, dateParser, datepickerPopupConfig, $timeout) {
return {
restrict: 'EA',
require: 'ngModel',
Expand Down Expand Up @@ -749,9 +749,11 @@ function ($compile, $parse, $document, $position, dateFilter, dateParser, datepi

scope.$on('$destroy', function() {
if (scope.isOpen === true) {
scope.$apply(function() {
scope.isOpen = false;
});
if (!$rootScope.$$phase) {

This comment has been minimized.

Copy link
@RobJacobs

RobJacobs Aug 3, 2015

Contributor

I wonder if $evalAsync or $applyAsync would accomplish the same thing?

scope.$apply(function() {
scope.isOpen = false;
});
}
}

$popup.remove();
Expand Down

0 comments on commit 74a8be4

Please sign in to comment.