1

The following snippet returns the following error: TypeError: object is not a function

service.deleteItem = function(itemId) {
    var def = $q.defer();
    $http.delete(SERVER_REST_PATH + '/items/' + itemId)
        .success(function() {
            def.resolve();
        }).error(function(data, status) {
            def.reject("Error deleting the item");
        });
    return def.promise();
};

If I rewrite it as the following it works:

service.deleteItem = function(itemId) {
    return $http.delete(SERVER_REST_PATH + '/items/' + itemId);
};

All other $http methods that I use(i.e GET, PUT, POST) in my app are wrapped with the $q the same way and they don't have this issue. Only the DELETE is causing this issue. When I debug it it just skips the $http's success(), error() and then() methods. I'm using angular version 1.3.13.

1
  • How do you use service.deleteProfile? Share the code where you call this function. Mar 7, 2015 at 16:40

1 Answer 1

2

change return def.promise(); to return def.promise;

example :

function deferredTimer(success) {
  var deferred = $q.defer();

  $timeout(function() {
    if (success) {
      deferred.resolve({ message: "This is great!" });
    } else {
      deferred.reject({ message: "Really bad" });
    }
  }, 1000);

  return deferred.promise;
}
2
  • 1
    Just didn't saw it. Looking everywhere but not this. Working during the weekend is no good ;) Thanks! Mar 7, 2015 at 16:46
  • i had also made same mistake.. so thats the first thing i checked :)
    – harishr
    Mar 7, 2015 at 16:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.