Skip to content

Commit

Permalink
fix(typeahead): resolve property length of undefined error
Browse files Browse the repository at this point in the history
- resolves property length of undefined error by checking value first angular-ui#2999

Fixes angular-ui#2999
Closes angular-ui#3178
  • Loading branch information
unkleara authored and ayakovlevgh committed Mar 24, 2015
1 parent 5750a42 commit 71c5dc0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
11 changes: 10 additions & 1 deletion src/typeahead/test/typeahead.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,15 @@ describe('typeahead tests', function () {
expect(element).toBeClosed();
});

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

deferred.resolve();
$scope.$digest();
expect(element).toBeClosed();
});

});

describe('non-regressions tests', function () {
Expand Down Expand Up @@ -777,7 +786,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

0 comments on commit 71c5dc0

Please sign in to comment.