From 74a8be4c5ad996b09eda9fd98faa52bbd901f289 Mon Sep 17 00:00:00 2001 From: Wesley Cho Date: Sun, 2 Aug 2015 09:56:08 -0700 Subject: [PATCH] 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 --- src/datepicker/datepicker.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/datepicker/datepicker.js b/src/datepicker/datepicker.js index ec299d545b..e9da91e0d6 100644 --- a/src/datepicker/datepicker.js +++ b/src/datepicker/datepicker.js @@ -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', @@ -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) { + scope.$apply(function() { + scope.isOpen = false; + }); + } } $popup.remove();