On Tue, Oct 28, 2014 at 9:23 AM, 'Michael Bielski' via AngularJS <
[email protected]> wrote:

> I can't speak for the OP, but we abstracted the inner workings of the
> $resource away by putting them into a service and wrapping every resource
> call in $q. Something like this:
>
> function doSomething(){
>      var defObj = $q.defer();
>
>      var Promise = myResource.query();
>      Promise.$promise.then(function(data){
>          defObj.resolve(data);
>      });
>
>      return defObj.promise;
> }
>
>
In this code, Promise.$promise is already a promise that resolves to the
right thing. What you are getting by creating a new promise around it? You
could replace the above with:

function doSomething() {
  return myResource.query().$promise;
}

This also solves the original problem, of wanting to return a promise
instead of an object with $promise in it.


-- 
Kyle Cordes
http://kylecordes.com

-- 
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