diff --git a/src/typeahead/test/typeahead.spec.js b/src/typeahead/test/typeahead.spec.js index a6d7db188e..d15d1e9860 100644 --- a/src/typeahead/test/typeahead.spec.js +++ b/src/typeahead/test/typeahead.spec.js @@ -196,6 +196,24 @@ describe('typeahead tests', function() { expect(element).toBeClosed(); }); + + it('should support changing min-length', function() { + $scope.typeAheadMinLength = 2; + var element = prepareInputEl('
'); + changeInputValueTo(element, 'b'); + expect(element).toBeClosed(); + $scope.typeAheadMinLength = 0; + $scope.$digest(); + changeInputValueTo(element, ''); + expect(element).toBeOpenWithActive(3, 0); + $scope.typeAheadMinLength = 2; + $scope.$digest(); + changeInputValueTo(element, 'b'); + expect(element).toBeClosed(); + }); + + + it('should support custom model selecting function', function() { $scope.updaterFn = function(selectedItem) { return 'prefix' + selectedItem; diff --git a/src/typeahead/typeahead.js b/src/typeahead/typeahead.js index acc7d1df75..c2b34159b5 100644 --- a/src/typeahead/typeahead.js +++ b/src/typeahead/typeahead.js @@ -38,7 +38,10 @@ angular.module('ui.bootstrap.typeahead', ['ui.bootstrap.debounce', 'ui.bootstrap if (!minLength && minLength !== 0) { minLength = 1; } - + originalScope.$watch(attrs.typeaheadMinLength, function (newVal) { + minLength = !newVal && newVal !== 0 ? 1 : newVal; + }); + //minimal wait time after last character typed before typeahead kicks-in var waitTime = originalScope.$eval(attrs.typeaheadWaitMs) || 0;