Skip to content
This repository was archived by the owner on May 29, 2019. It is now read-only.

Commit 950c22c

Browse files
unklearachrisirhc
authored andcommitted
fix(typeahead): resolve property length of undefined error
- resolves property length of undefined error by checking value first #2999 Fixes #2999 Closes #3178
1 parent 36e6363 commit 950c22c

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

src/typeahead/test/typeahead.spec.js

+10-1
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,15 @@ describe('typeahead tests', function () {
487487
expect(element).toBeClosed();
488488
});
489489

490+
it('PR #3178, resolves #2999 - should not return property "length" of undefined for undefined matches', function () {
491+
changeInputValueTo(element, 'c');
492+
expect(element).toBeClosed();
493+
494+
deferred.resolve();
495+
$scope.$digest();
496+
expect(element).toBeClosed();
497+
});
498+
490499
});
491500

492501
describe('non-regressions tests', function () {
@@ -777,7 +786,7 @@ describe('typeahead tests', function () {
777786
};
778787
var element = prepareInputEl('<div><input ng-model="result" ng-keydown="keyDownEvent = $event" typeahead="item for item in source | filter:$viewValue" typeahead-on-select="onSelect($item, $model, $label)" typeahead-focus-first="false"></div>');
779788
changeInputValueTo(element, 'b');
780-
789+
781790
// enter key should not be captured when nothing is focused
782791
triggerKeyDown(element, 13);
783792
expect($scope.keyDownEvent.isDefaultPrevented()).toBeFalsy();

src/typeahead/typeahead.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ angular.module('ui.bootstrap.typeahead', ['ui.bootstrap.position', 'ui.bootstrap
131131
//but we are interested only in responses that correspond to the current view value
132132
var onCurrentRequest = (inputValue === modelCtrl.$viewValue);
133133
if (onCurrentRequest && hasFocus) {
134-
if (matches.length > 0) {
134+
if (matches && matches.length > 0) {
135135

136136
scope.activeIdx = focusFirst ? 0 : -1;
137137
scope.matches.length = 0;
@@ -172,7 +172,7 @@ angular.module('ui.bootstrap.typeahead', ['ui.bootstrap.position', 'ui.bootstrap
172172
//we need to propagate user's query so we can higlight matches
173173
scope.query = undefined;
174174

175-
//Declare the timeout promise var outside the function scope so that stacked calls can be cancelled later
175+
//Declare the timeout promise var outside the function scope so that stacked calls can be cancelled later
176176
var timeoutPromise;
177177

178178
var scheduleSearchWithTimeout = function(inputValue) {

0 commit comments

Comments
 (0)