Angular Js 405 DELETE方法未被评估

时间:2017-01-08 15:19:43

标签: javascript c# angularjs http-delete http-method

我在Angular中有以下代码

DepartmentController.prototype.delete = function (id) {
    this.departmentResource.delete(id);
};

错误是

DELETE http://localhost:64956//api/departments 405 (Method Not Allowed)

我的部门工厂是:

 var Company;
    (function (Company) {
        function departmentFactory($resource, servicePath) {
            return $resource(servicePath + "/api/departments/:serverAction/:id", null, Company.DepartmentResourceActionDescriptors.actions);
        }
        Company.departmentFactory = departmentFactory;
        departmentFactory.$inject = ['$resource', 'servicePath'];
    })(Company || (Company = {}));

我从控制器调用delete方法后放了一个断点,id看起来没问题。有人可以帮帮我吗?

1 个答案:

答案 0 :(得分:0)

您没有传递serverAction,这是您编写资源工厂所必需的。

使用:

params {
    serverAction: { squash: true, value: null }
}
在您的资源中

使其成为可选项。 并删除/ api的斜杠。

B.t.w。无论如何,serverAction是什么?您可能想要删除(?)