Cannot read response from AngularJS $resource DELETE

情到浓时终转凉″ 提交于 2019-12-06 07:49:04

Using resources can be a bit confusing (at least they originally were for me).

I think your problem is that your call to delete isn't using the correct signature (there are different signatures for 'GET' methods and 'non-GET' methods. In this case, it looks like you are sending what is intended to be your callback function (for success and error) as postData. The signature you used is for 'GET' methods (which doesn't have postData).

The signature for your call to delete should look like this (see documentation here):

Resource.action([parameters], postData, [success], [error])

So, you can do something like this:

quizcatControllers.controller('BBBCtrl', ['$scope', '$stateParams', '$http', 'AAAService', 
function($scope, $stateParams, $http, AAAService) {
    $scope.deleteQuestion = function(user, videoId) {
        AAAService.delete(
            {userId: user, videoId: videoId},  // parameters
            {},                                // postData, which you don't need for this
            // success callback
            function (returnValue, responseHeaders) {
                // do what you want with the returnValue from the call here
            },
            // error callback
            function (httpResponse) {
                // do what you want for error handling here
            })
    };
}]);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!