Wednesday 7 August 2013

AngularJS ui typehead not working with http

AngularJS ui typehead not working with http

I've been trying to make the AngularJS ui typehead work with my backend
but had no success.
In my partial:
<input type="text" ng-model="selected" typeahead="language.id as
language.name for language in getLanguages($viewValue) |
filter:$viewValue"/>
In my controller:
$scope.getLanguages = function(search) {
// This works:
return [{"id":"15","name":"Norwegian
(Bokm\u00e5l)","short":"no"},{"id":"45","name":"Norwegian
(Nynorsk)","short":"nn"}];
// This doesn't work:
return $http.get('/json/suggest/languages/' +
search).success(function(response) {
return response;
});
}
As you can see it works when I define the response statically in JS but
not when it's retrieved from backend. The static response is copy-pasted
from backend response. Http request is working, I can see the response in
developer tools, format is correct but typehead doesn't appear. Any idea
why this happens?
Thanks!

No comments:

Post a Comment