From 0d96221fa32794deb702d1b923ae38f11f5b66a4 Mon Sep 17 00:00:00 2001 From: Wesley Cho Date: Wed, 10 Jun 2015 06:48:49 -0700 Subject: [PATCH] fix(typeahead): do not execute unnecessary $digest - If in a $digest, do not execute `scope.$digest` Fixes #2652 Closes #3791 --- src/typeahead/typeahead.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/typeahead/typeahead.js b/src/typeahead/typeahead.js index 1fe28401ab..994a7b2e79 100644 --- a/src/typeahead/typeahead.js +++ b/src/typeahead/typeahead.js @@ -29,8 +29,8 @@ angular.module('ui.bootstrap.typeahead', ['ui.bootstrap.position', 'ui.bootstrap }; }]) - .directive('typeahead', ['$compile', '$parse', '$q', '$timeout', '$document', '$position', 'typeaheadParser', - function ($compile, $parse, $q, $timeout, $document, $position, typeaheadParser) { + .directive('typeahead', ['$compile', '$parse', '$q', '$timeout', '$document', '$rootScope', '$position', 'typeaheadParser', + function ($compile, $parse, $q, $timeout, $document, $rootScope, $position, typeaheadParser) { var HOT_KEYS = [9, 13, 27, 38, 40]; @@ -318,7 +318,9 @@ angular.module('ui.bootstrap.typeahead', ['ui.bootstrap.position', 'ui.bootstrap var dismissClickHandler = function (evt) { if (element[0] !== evt.target) { resetMatches(); - scope.$digest(); + if (!$rootScope.$$phase) { + scope.$digest(); + } } };