Jackie
Jackie

Reputation: 23477

How to handle autocomplete in Angular.JS from JSON feed

I am working on implementing autocomplete for a text box similar to what is done here. The main difference being I want mine to come from a service returning a list. Here is the code I use...

  //How I would like it to work...
  $scope.search=function(query){
    $http.get('/product/query/name%3A'+query+'*').success(function(data){
      // For a data is ["a","a1"]
      $scope.names = data;
    })
  }
  //Trying to get it to work by not using the ng-change event but still no dice
  $http.get('/product/query/name%3A*').success(function(data){
      //Data when printed does in fact match the ["a","a1", "b"]
      $scope.names = data;
  });
  //finally this DOES work but not dynamic
  $scope.names =["a","a1", "b"];

Anyone able to provide some insight as to what I am missing?

Upvotes: 1

Views: 1175

Answers (1)

Jossef Harush Kadouri
Jossef Harush Kadouri

Reputation: 34207

you can use typeahead which is part of angular-ui library

http://plnkr.co/edit/08vi4ncjLrWfUBjWrZKS?p=preview

enter image description here

Upvotes: 2

Related Questions