Is this still applicable at version 1.2.16? Thanks.
On Thursday, September 13, 2012 12:53:33 AM UTC+8, 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.