I am getting the following error when I attempt to get a typeahead values from AngularUI-Bootstrap, using a promise.
TypeError: Cannot read property \'length
$scope.getTypeaheadValues is not returning any array. It returns null, because your return statement is in the callback function "success", which is called asynchrony.
Maybe this will work:
$scope.getTypeaheadValues = function($viewValue)
{
var output = [];
$http({
method: 'GET',
url: 'api/v1/person?name__icontains=' + $viewValue
}).error(function ($data) {
console.log("failed to fetch typeahead data");
}).success(function ($data) {
$data.objects.forEach(function (person)
{
output.push(person.name);
});
console.log(output);
});
return output;
}