The DELETE method is not permitted in Angular JS 405

I'm encountering an issue with my Angular code:

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

The error message I'm receiving is:

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

This is my department factory:

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

After setting a breakpoint following the call to the delete method from the controller, the id parameter appears to be correct. Can anyone provide assistance?

Answer №1

It appears that you have not included the serverAction parameter, which is necessary based on how your resource factory is currently set up.

Please try using the following:

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

This will make the serverAction parameter optional in your resource. Also, remember to remove the slash from /api.

By the way, do you know what the purpose of the serverAction parameter is? You may want to consider removing it(?))

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Generating and Retrieving Dynamic URL with Jquery

My web page named single-colur.html has the ability to handle various query strings, such as: single-colour.html?id=1 single-colour.html?id=2 single-colour.html?id=3 single-colour.html?id=4 The parameter id in the URL corresponds to an entry in a table c ...

The unusual behavior of the :to attribute on @click in Vue

I have a specific element: Hashtag.vue: <template> <router-link :to="getTo" custom v-slot="{ navigate }"> <div role="link" @click="navigate"> {{text}}</div> </rout ...

How can I utilize customToJSON in Sails 1.0 within an Action2 function?

Currently, I am facing an issue with my user model that requires the implementation of a customToJSON method to remove the password field from the returned JSON object. Everything works fine when I include "responseType" in the "exits" with a value of "jso ...

The view height appears to be incorrect when the browser's developer tools are opened

The background height appears correct, however, when the console is opened, the background shifts upwards creating white space. I have tried setting both height: 100% and height:100vh, but the issue persists. Click here for image description .main { ...

Verify using .NET framework whether Remote Desktop Services (RDS) or Remote Desktop Session Host (RDSH) has been installed on a Windows Server

Looking to determine using .NET whether Remote Desktop Session Host has been installed on a Windows server from 2008 to 2019 as a prerequisite check for our software. Due to restrictions on installing certain components in execution mode on a RDS Server, ...

Retrieve the output of a JavaScript onclick event

Does anyone know how to scrape the URL generated by a JavaScript onclick function on a website without opening new tabs or windows? I think Selenium might work, but I'm not sure how to code it. Here is the onclick JS function: 'tr class="linha ...

Leveraging Jquery and an API - restricted

I have the opportunity to utilize a search API that operates on JSON format through a URL GET. This particular API has a reputation for imposing quick bans, with an appeal process that can be lengthy. If I were to integrate this API into my website using ...

What is the best way to determine the size of a returned element in React?

How can I determine if the description of {book.volumeInfo.description} is empty or not? If the length of {book.volumeInfo.description} is greater than zero, display it; otherwise, show "Book without description". I am unsure of the correct way to get the ...

Guide to resizing and shifting to the right using CSS techniques

As a backend developer with experience in nodejs, I am diving into the world of web application development. HTML5 and CSS are new territories for me, but you can check out my small web application here. Now, I am looking to incorporate animations into my ...

Is it feasible to incorporate controls into a WebUserControl from an ASPX page?

As an illustration, the custom user control I developed is a dock panel. I am interested in enabling it to accept additional controls from the aspx page. <uc1:dockPanel ID="dockPanel1" runat="server"> --insert controls here from the aspx pa ...

Prevent the occurrence of the dreaded 'undefined property' error when attempting to validate a grandchild property

I need to set the state of a React component to the location.state passed with React Router. If it doesn't exist, I want to set it to 0. However, in some cases, the parent (location.state) of the property I am checking for (currentItem) doesn't ...

Tips for truncating a long string on Firefox for a responsive design

Can someone help me figure out how to display a 2-line image text below? Sample Image This is what it looks like in Chrome, but unfortunately, it doesn't work in Firefox. I came across a website that has a tutorial for Chrome: https://css-tricks.com/ ...

What steps should I take to implement two-way binding for a contenteditable element using ng-bind-html in AngularJS?

I'm still learning Angularjs and came across the code snippet below in the documentation. I am curious how I can modify this to utilize ng-bind-html instead of ng-model. Will there be a conflict if I use both ng-bind-html and ng-model simultaneously? ...

Altering the display attribute cancels out any opacity transitions

When using JavaScript to change the opacity of an element with transition: opacity 1s, the expected duration of one second is met, as demonstrated here: onload = e => { var p = document.getElementsByTagName("p")[0]; p.style.opacity = 1; }; p { ...

Using a Javascript method to access a sibling property within an object

Is there a way to access a sibling property from a method in JavaScript? This seemingly simple task has proven challenging for me. Take a look at the sample code below. let f = { a: 3, printMyBrother() { console.log(X) } }.printMyBrother f() ...

Arranging json array according to alphabetical sections in angularjs 2

In the example below, I am working with JSON data that needs to be formatted and placed in a box according to specific criteria. The data sorted in A-B should go to a particular section, and it needs to be dynamic. Despite numerous attempts, I have not bee ...

Discovering a compilation of undisclosed attributes specified in Angular

I recently took over a large Angular project from another developer and noticed that there are many undeclared properties being assigned in the HTML markup without being declared in the controller. While I understand that Angular will still create these p ...

What is the best way to decompress a gzip response body from a NodeJS request module?

How can I decompress a gzipped body in a request's module response? I have attempted various methods from different sources online, but none of them seem to be effective. request(url, function(err, response, body) { if(err) { handleError ...

Unable to close the file upload window using Selenium

I've encountered a dilemma that I'm trying to solve. On my webpage, there's a screen that opens a dialog box for file upload. Although I managed to select the file, the dialog box refuses to close and remains open, preventing me from proceed ...

The issue of Ajax not refreshing the HTML content within a dynamically generated div using JavaScript

(using jQuery) 1) I have a JavaScript click event that generates a form with a dropdown and a div like the following: $('#closestDiv').on('click','.firstClick', function(event){ var pass = $(this).attr('data-pass' ...