pQuestions123
pQuestions123

Reputation: 4611

using angular $resource properly

Here is the code:

var dbDelivery = Deliveries.get({deliveryId: delivery.id}, function() {
                if (!dbDelivery.id) {
                    toaster.pop('error', 'Error', 'That delivery does not exist. Somebody else may have deleted it.');
                    var deliveryIndex = $rootScope._.findIndex($scope.deliveries, 'id', delivery.id);
                    $scope.deliveries.splice(deliveryIndex, 1);
                    return;
                }
                dbDelivery.confirmed = true;
                dbDelivery.$update(function() { delivery.confirmed = true; }, ServerErrorAlert);
                return dbDelivery.$promise;
            })

Questions: 1) What happens if one calls multiple resource methods on a resource and returns the $promise? Does it just depend on the last method executed? 2) What is $resource looking for in order to reject the promise? I mean does it just depend on the response status code? If so which status codes result in a success and which result in error?

Upvotes: 0

Views: 46

Answers (1)

fantarama
fantarama

Reputation: 880

1) You can chain promises, but every $resource method call generate a new promise that represent the called method promise

2) It resolve the promise if the http response code is a success code 2xx (see)

Upvotes: 1

Related Questions