diff --git a/src/typeahead/test/typeahead.spec.js b/src/typeahead/test/typeahead.spec.js index 1e2ec60b68..59f3f661aa 100644 --- a/src/typeahead/test/typeahead.spec.js +++ b/src/typeahead/test/typeahead.spec.js @@ -507,6 +507,25 @@ describe('typeahead tests', function () { expect(element).toBeClosed(); }); + it('should properly update loading callback if an element is not focused', function () { + + $scope.items = function(viewValue) { + return $timeout(function(){ + return [viewValue]; + }); + }; + var element = prepareInputEl('
'); + var inputEl = findInput(element); + + changeInputValueTo(element, 'match'); + $scope.$digest(); + + inputEl.blur(); + $timeout.flush(); + + expect($scope.isLoading).toBeFalsy(); + }); + it('issue 1140 - should properly update loading callback when deleting characters', function () { $scope.items = function(viewValue) { diff --git a/src/typeahead/typeahead.js b/src/typeahead/typeahead.js index e0cb5b9f6a..7148ce3031 100644 --- a/src/typeahead/typeahead.js +++ b/src/typeahead/typeahead.js @@ -110,7 +110,8 @@ angular.module('ui.bootstrap.typeahead', ['ui.bootstrap.position', 'ui.bootstrap //it might happen that several async queries were in progress if a user were typing fast //but we are interested only in responses that correspond to the current view value - if (inputValue === modelCtrl.$viewValue && hasFocus) { + var onCurrentRequest = (inputValue === modelCtrl.$viewValue); + if (onCurrentRequest && hasFocus) { if (matches.length > 0) { scope.activeIdx = 0; @@ -136,6 +137,8 @@ angular.module('ui.bootstrap.typeahead', ['ui.bootstrap.position', 'ui.bootstrap } else { resetMatches(); } + } + if (onCurrentRequest) { isLoadingSetter(originalScope, false); } }, function(){