I have a search button that when clicked will go to an external API to get 
a list of hotels.

Instead of making a http.get request to send the data along to my other 
page, the search button just fires off a function each time which will then 
make an ajax request. 

However when I try to get the data from the controller, it runs the 
function before the request has been made. How can I return the data to the 
controller only when the function has been made only from the search button?


*Controller*
hotelsFactory.getEanApi().then(function(data){
  $scope.data = data;
  console.log($scope.data);
 });

*Factory*
var deffered = $q.defer();
    var data = []; 

      $http.jsonp(url)
    .success(function (d) {
        data = d;
        deffered.resolve(data);
      });

    
    return deffered.promise;

-- 
You received this message because you are subscribed to the Google Groups 
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to