diff --git a/src/typeahead/test/typeahead.spec.js b/src/typeahead/test/typeahead.spec.js index a6d7db188e..6a06638dd9 100644 --- a/src/typeahead/test/typeahead.spec.js +++ b/src/typeahead/test/typeahead.spec.js @@ -196,6 +196,30 @@ 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..6cf678b40a 100644 --- a/src/typeahead/typeahead.js +++ b/src/typeahead/typeahead.js @@ -39,6 +39,10 @@ angular.module('ui.bootstrap.typeahead', ['ui.bootstrap.debounce', 'ui.bootstrap 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;