16

In material design autocomplete(https://material.angularjs.org/#/demo/material.components.autocomplete) All examples show how to get data from local variable. There is no help on doing auto complete via AJAX call.

Cyril Cherian
  • 32,177
  • 7
  • 46
  • 55
  • It does not matter where you get the data from. Post your code – Sajeetharan Apr 08 '15 at 10:39
  • Hello sajeetharan, The example is here in source https://material.angularjs.org/#/demo/material.components.autocomplete I just need a mechanism to make it a remote call rather than looking in the local variable. – Cyril Cherian Apr 08 '15 at 10:49
  • 1
    Just make an $http call and get the data – Sajeetharan Apr 08 '15 at 10:51
  • Yes! i am doing the $http but it is asynchronous i need to return something from the called function. The function return as per the example is an expected array. – Cyril Cherian Apr 08 '15 at 10:56

1 Answers1

24

You just need to use a function that returns a promise in md-items. See this plunk: http://plnkr.co/edit/KFQg53ZVfPAMum0dFctK?p=preview

NOTE: Returned promises from $http will be resolved with an object that has the data. So you have to do something like this:

    return $http.get(url).then(function(response){
         return response.data.someOtherPathMaybe; // usually response.data
    })
Alireza Mirian
  • 5,862
  • 3
  • 29
  • 48