Often when you want to make multiple REST calls and wait for them to complete before rendering a new view, the best approach is to use routes and the resolve property.
On Wed, Aug 27, 2014 at 11:51 AM, Darren D'Orlando < [email protected]> wrote: > This approach seems to work really well, when you have to call multiple > rest services to get the data to populate a page. In other words, if I > want to call two web services, but I don't want to show data until both > responses come back. > > On Wednesday, September 12, 2012 10:53:33 AM UTC-6, Uri Goldshtein wrote: >> >> Hi, >> >> I've created a service that calls $http (not $resource) and to get the >> value to the controller. >> It took some time and i found a lot of example but not exactly what i >> needed. >> Maybe this will help someone: >> >> The service: >> >> angular.module('myApp.services', []). >> service('Activities', function($http, $q) { >> this.get = function(from, to){ >> var deferred = $q.defer(); >> var url = 'user/activities?from='+from+'&to='+to; >> $http.get(url).success(function(data, status) { >> // Some extra manipulation on data if you want... >> deferred.resolve(data); >> }).error(function(data, status) { >> deferred.reject(data); >> }); >> >> return deferred.promise; >> } >> } >> ); >> >> >> The call inside the controller (don't forget to DI the service in the >> controller's parameters): >> >> var promise = Activities.get(now, monthAgo); >> promise.then( >> function(activities){$scope.transactions = activities;} >> ,function(reason){alert('Failed: ' + reason);} >> ); >> >> >> -- > 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. > -- R. Mark Volkmann Object Computing, Inc. -- 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.
