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

fix(typeahead): resolves property length of undefined error #2999 #3178

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/typeahead/test/typeahead.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,14 @@ describe('typeahead tests', function () {
expect(element).toBeClosed();
});

it('PR #3178, resolves #2999 - should not return property "length" of undefined for matches', function () {
changeInputValueTo(element, 'c');
expect(element).toBeClosed();

expect(deferred.resolve()).toEqual(undefined);
$scope.$digest();
});

});

describe('non-regressions tests', function () {
Expand Down Expand Up @@ -741,7 +749,7 @@ describe('typeahead tests', function () {
};
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>');
changeInputValueTo(element, 'b');

// enter key should not be captured when nothing is focused
triggerKeyDown(element, 13);
expect($scope.keyDownEvent.isDefaultPrevented()).toBeFalsy();
Expand Down
4 changes: 2 additions & 2 deletions src/typeahead/typeahead.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ angular.module('ui.bootstrap.typeahead', ['ui.bootstrap.position', 'ui.bootstrap
//but we are interested only in responses that correspond to the current view value
var onCurrentRequest = (inputValue === modelCtrl.$viewValue);
if (onCurrentRequest && hasFocus) {
if (matches.length > 0) {
if (matches && matches.length > 0) {

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

//Declare the timeout promise var outside the function scope so that stacked calls can be cancelled later
//Declare the timeout promise var outside the function scope so that stacked calls can be cancelled later
var timeoutPromise;

var scheduleSearchWithTimeout = function(inputValue) {
Expand Down