1

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?

1
  • 1
    try to create a factory and do the http call from factory and then assign the results to scope.name Commented Jul 6, 2014 at 19:35

1 Answer 1

2

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

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

enter image description here

Sign up to request clarification or add additional context in comments.

5 Comments

just an FYI, plunker link is no good now, they use a post to send code to plunker when you click "edit in plunker"
I will take a look thanks, any idea why this situation is failing?
So I tried this out and I am about ready to give the check. The last thing I am struggling with is how would I use an attribute. For example if I need a name and an ID to map back to the object? This example just pushes a single value. So in this sample I need the formatted address along with the address id
Would something like typeahead="address.name for address in getLocation($viewValue)" work?
@Jackie, here's a new plunk with your desires :) plnkr.co/edit/5OeZ7e7Q6jYP2LkKN1jm?p=preview

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.