Skip to content

Commit

Permalink
Fix: down-arrow and enter key throwing error when input field is empty
Browse files Browse the repository at this point in the history
  • Loading branch information
ghiden committed Mar 10, 2014
1 parent 5b070bd commit 83c2509
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions angucomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ angular.module('angucomplete', [] )

elem.on("keyup", function (event) {
if(event.which === 40) {
if (($scope.currentIndex + 1) < $scope.results.length) {
if ($scope.results && ($scope.currentIndex + 1) < $scope.results.length) {
$scope.currentIndex ++;
$scope.$apply();
event.preventDefault;
Expand All @@ -200,7 +200,7 @@ angular.module('angucomplete', [] )
}

} else if (event.which == 13) {
if ($scope.currentIndex >= 0 && $scope.currentIndex < $scope.results.length) {
if ($scope.results && $scope.currentIndex >= 0 && $scope.currentIndex < $scope.results.length) {
$scope.selectResult($scope.results[$scope.currentIndex]);
$scope.$apply();
event.preventDefault;
Expand Down

0 comments on commit 83c2509

Please sign in to comment.