Error in AngularJS-Bootstrap TypeAhead: TypeError: Cannot read property 'length' of undefined Error in AngularJS-Bootstrap TypeAhead: TypeError: Cannot read property 'length' of undefined angularjs angularjs

Error in AngularJS-Bootstrap TypeAhead: TypeError: Cannot read property 'length' of undefined


after second look at code I've noticed what's wrong, you have to return $http promise here, notice return before $http

$scope.fetchUsers = function(val) {        console.log("Entered fetchUsers function");        return $http.get("http://localhost:8080/TestWeb/users", {            params : {                username : val            }        }).then(function(res) {            var users = [];            angular.forEach(res.data, function(item) {                users.push(item.UserName);            });            return users;        });    };