From 31e283d1df9c780848b844537efa7641a993da2f Mon Sep 17 00:00:00 2001 From: Joaquim Pedro Silveira Date: Thu, 16 Oct 2014 20:01:29 -0300 Subject: [PATCH] Update datepicker.js Fix for issue #2789 where it was throwing "$apply already in progress" when using ng-focus to open the popup. --- src/datepicker/datepicker.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/datepicker/datepicker.js b/src/datepicker/datepicker.js index 05784947d0..50bc0140d0 100644 --- a/src/datepicker/datepicker.js +++ b/src/datepicker/datepicker.js @@ -524,6 +524,13 @@ function ($compile, $parse, $document, $position, dateFilter, dateParser, datepi } ngModel.$parsers.unshift(parseDate); + function closeWithFocus() { + $timeout(function () { + scope.isOpen = false; + element[0].focus(); + }, 0, false); + } + // Inner change scope.dateSelection = function(dt) { if (angular.isDefined(dt)) { @@ -533,8 +540,7 @@ function ($compile, $parse, $document, $position, dateFilter, dateParser, datepi ngModel.$render(); if ( closeOnDateSelection ) { - scope.isOpen = false; - element[0].focus(); + closeWithFocus(); } }; @@ -600,8 +606,7 @@ function ($compile, $parse, $document, $position, dateFilter, dateParser, datepi }; scope.close = function() { - scope.isOpen = false; - element[0].focus(); + closeWithFocus(); }; var $popup = $compile(popupEl)(scope);