angular ui - AngularJS ui typehead not working with http -


i've been trying make angularjs ui typehead work backend had no success.

in partial:

<input type="text" ng-model="selected" typeahead="language.id language.name language in getlanguages($viewvalue) | filter:$viewvalue"/> 

in controller:

$scope.getlanguages = function(search) {   // works:   return [{"id":"15","name":"norwegian (bokm\u00e5l)","short":"no"},{"id":"45","name":"norwegian (nynorsk)","short":"nn"}];    // doesn't work:   return $http.get('/json/suggest/languages/' + search).success(function(response) {     return response;   }); } 

as can see works when define response statically in js not when it's retrieved backend. static response copy-pasted backend response. http request working, can see response in developer tools, format correct typehead doesn't appear. idea why happens?

btw, i've used plunker example: http://plnkr.co/edit/egg9kj?p=preview

thanks!

there 2 problems in code:

  • you using success not return promise, change then instead;
  • after above change need return data instead of whole response.

change code so:

return $http.get('/json/suggest/languages/' + search).then(function(response) {     return response.data; }); 

Comments

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -