Angular Js 405 DELETE Method Not Alowed

447 views Asked by At

I have the following code in Angular

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

The error is

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

My department factory is :

 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 = {}));

I put a breakpoint after call delete method from controller and the id looks ok . Can anyone help me please?

1

There are 1 answers

0
Norbert Huurnink On

You're not passing serverAction, which is required the way you wrote your resource factory.

Use:

params {
    serverAction: { squash: true, value: null }
}

in your resource to make it optional. And remove the slash of /api.

B.t.w. what is serverAction for anyway? You might want to remove that(?)