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

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -