title: angular ui typeahead data over http rest service
body: <p>in my html I have </p>
  
  <pre><code>typeahead="name for name in search($viewValue)
  </code></pre>
  
  <p>My data returned from server is as expected. But I have now realised that as this is a async request, the return I am doing in multiple places in the code below are worthless, as they are not returning the data array so that the html code above can receive it.</p>
  
  <pre><code>        $scope.search = function (term) {
              return $http({
                  method: 'GET',
                  url: 'rest/search',
                  params: {
                      term: term,
                      types: '21'
                  }
              }).
              success(function (data, status, headers, config) {
                  var Names = [];
                  for (var i = 0; i &lt; data.length; i++) {
                      Names.push(data[i].name);
                  }
                  console.log(Names);//as expected
  
                  return Names;
              }).
              error(function (data, status, headers, config) {
                  console.log(status);
              });
  
          };
  </code></pre>
  
  <p>How should I return the data from a async HTTP GET request in an array form so that my typeahead can use it.</p>
  
  <p>Should I store in a data variable like this example on HTTP GET success <a href="https://stackoverflow.com/a/12513509/494461">https://stackoverflow.com/a/12513509/494461</a></p>
  
  <p>but then how can I run the function as well use the storage variable in the array?</p>
  
  <pre><code>typeahead="name for name in search($viewValue)
  </code></pre>
  
  <p>or</p>
  
  <pre><code>typeahead="name for name in dataStoredInHTTPGetSucess
  </code></pre>
  
  <p>can I somehow combine the above two?</p>