1

I made some minor modifications to the angular-ui typeahead example provided in http://angular-ui.github.io/bootstrap/

Here is the original code inside the controller.

  $scope.getLocation = function(val) {
    return $http.get('http://maps.googleapis.com/maps/api/geocode/json', {
      params: {
        address: val,
        sensor: false
      }
    }).then(function(res){
      var addresses = [];
      angular.forEach(res.data.results, function(item){
        addresses.push(item.formatted_address);
      });
      return addresses;
    });
  };

Here are the changes I made;

  $scope.getLocation = function(val) 
  {
    return $http.get('http://maps.googleapis.com/maps/api/geocode/json', 
    {
      params: 
      {
        address: val,
        sensor: false
      }
    }).success(function(data, status, headers, config)
    {
      var addresses = [];
      angular.forEach(data.results, function(item){
        addresses.push(item.formatted_address);
      });
      return addresses;
    });
  };

What is wrong with my code? I did not get any error. The typeahead just did not work. I don't see any typeahead text as I type in the text inside the inputbox.

Thanks.

guagay_wk
  • 26,337
  • 54
  • 186
  • 295
  • 1
    This isn't a quiz site, can you let us know what the error is? – Mutahhir May 21 '14 at 05:10
  • Sorry, I am still a newbie. I did not get any error. The typeahead just did not work. I don't see any typeahead text as I type in the text inside the inputbox. – guagay_wk May 21 '14 at 05:11
  • Ok, that helps, you should edit the answer to let people know why you think your code is wrong. – Mutahhir May 21 '14 at 05:13

1 Answers1

3

The .success() method does not actually return a promise which is what the typeahead api expects. The .then() method does return a promise. See this answer for more details about the difference between .success() and .then().

Community
  • 1
  • 1
JoseM
  • 4,302
  • 2
  • 24
  • 35