Why is $httpBackend failing to populate parameters?

In my application, I utilize a custom $resource service to manage CRUD operations for entities over HTTP. The service is simply wrapped in a custom service without additional functionality:

app.factory('coursesService', ['$resource', coursesService]);

function coursesService($resource) {
    return $resource('/api/courses/:id', {
  id: '@id'
}, {
  update: {
    method: 'PUT'
  }
});

Attempting to delete an instance in the controller (stored in courseToDelete):

this.courseToDelete.$remove()

To simulate backend behavior, I make use of the $httpBackend service from the ngMockE2E module:

$httpBackend.whenDELETE(/api\/courses\/(.+)/, undefined, undefined, ['id'])
  .respond(function(method, url, data, headers, params) {
    clientStorage.deleteCourse(params.id);
    return [200, {}];
  });

When a DELETE request is sent via $resource, I intend to remove it from local storage (as there is no actual backend, data is stored as serialized JSON):

The object being deleted:

 {
      id: 1,
      name: 'Course 1',
      duration: 380,
      description: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.' +
      ' Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.' +
      ' Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur' +
      ' sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.',
      created: new Date(2011,10,30),
      authors: [
        'Пушкин', 'Лермонтов'
      ]
    }

Although all other parameters appear correct, when the function runs, the params parameter is unexpectedly undefined instead of containing the expected id property. Any insights on what might be incorrect in this setup?

Answer №1

This information is sourced from the Angular $httpBackend documentation.

whenDELETE(url, [headers], [keys])

However, you seem to be using

whenDELETE(url, undefined, undefined, [keys])

Therefore, your keys argument is undefined and no parameters are being passed.

UPDATE: It should be noted that this feature was not implemented for versions 1.4.8 and earlier.

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

Tips for managing static resources using webpack on the server side?

I am currently working on developing a universal React app that utilizes webpack for both server and client-side operations. One issue I am facing involves importing images into the project. I would like to achieve the following: import someImage from &ap ...

What is the method for locating all anchor tags "In General" within the inner HTML of a div using XPath?

This query is related to a discussion on anchor tags in this thread. I am interested in identifying all anchor tags within a string. The scenario provided below is similar to the aforementioned issue, however, I aim to accomplish this using xpath and angu ...

Is it possible to pass URL parameters using request.get method in Python?

Here is the required URL structure for the API: https://.../api/v1/users/getprofile?access_token={{access_token}} This is how I attempted to call the API using request: const request = require('request'); request.get("https://.../api/v1/use ...

Removing elements from an array with reduced speed

Within my array, I am looking to remove N elements from the beginning. For instance, if my array contains 1 million floating point elements and I need to remove the first 500,000, I have two options. The first is to iterate and call the shift method 500,0 ...

Ways to call a method in a subclass component from a functional parent component?

In my redux-store, I have objects with initial values that are updated in different places within the child component. As the parent, I created a stateless functional component like this: const Parent = () => { const store = useSelector(state => s ...

Experiencing difficulties with the createClient function

Let me explain how my code functions: in the index.js file, a discord bot stores usernames and passwords. When I send a request to the minecraft file using minecraft-protocol, it establishes a login to a server named Client. clientName = mc.create ...

iOS now supports fully transparent tooltips and modals, offering a sleek and

I am currently working on developing tooltips and modals for an iOS app using react-native. The problem I am encountering is that the background of the tooltips and modals is not transparent, although it appears correctly on the Android version of the app. ...

Tips for dynamically loading fresh Google Adsense code with JavaScript without any user interaction

Recently, Google made a change in their ad code by replacing <script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js</script> with <script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygo ...

The process of raycasting with specific points within a collection of points in a Three.js Point

I am facing an issue with my PointCloud object. I want to draw a bounding box around a specific point when clicked, but I can't figure out how to access that individual point within the PointCloud. This is the raycasting code snippet I have been usin ...

I lingered a moment too long on the left and right buttons of my Carousel

Currently facing an issue with a slideshow feature where the images are not smoothly transitioning when using the left/right buttons. The transition is either delayed, slow, or causes the page to hang. Additionally, after some time, the images automaticall ...

Got a not-a-number (NaN) value for the `children` prop in a

Just starting out with React and working on a type racer app. I've encountered an issue while trying to calculate WPM (Words per minute) - the calculation keeps returning 'NaN'. I've double-checked all the variables and ensured there ar ...

What is the best way to enforce constraints on three keys when validating an object using Joi?

Currently experimenting with Joi for object validation. Able to validate objects with constraints on two keys using any.when(). Now looking to implement validation with constraints on three keys, for example: var object = { dynamicPrize: false, ...

Are you facing issues with Handlebars parsing?

I am struggling to identify the issue in my HTML/JS code. Here is my HTML/JS: <html> <head> <script src="http://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script> <script src="handlebars-v1.1.2.js"> ...

Error encountered in a Node.js Express application: 'Error in Jade template (version 1.0+): The usage of duplicate key "id" is not permitted.'

Seeking guidance on the following issue: Within my Express app, I am providing numerous parameters to a Jade template, resulting in an error message that states: Duplicate key "id" is not allowed. (After reviewing, I have confirmed that there is no para ...

I am facing an issue where the TailwindCSS styles seem to be malfunctioning in my Next

After building a Next.js application and following the instructions in the documentation to integrate TailwindCSS, I encountered a problem. Despite completing the integration process successfully, the web page did not display any of the expected TailwindCS ...

Using jQuery to Decode the XML Document Containing National Threat Level Data

Recently, I've been experimenting with using jQuery to extract data from the DHS Threat Level found in their XML file. However, despite my efforts, I haven't been able to make it work. As a newcomer to Javascript and non-presentational jQuery, I& ...

A step-by-step guide on extracting values from JSON using JavaScript

I am facing a challenge in extracting values from a JSON string. The JSON string I have is: {"user":{"id":"1","firstname":"Freelogin","created":"0000-00-00 00:00:00","lastname":"Administrator","email":"<a href="/cdn-cgi/l/email-protection" class="__cf_ ...

Issue with NodeJS SQL Login: Received error (ERR_HTTP_HEADERS_SENT): Headers cannot be set after being sent to the client

Hi there, I am fairly new to working with nodeJS and I have encountered an issue that I suspect lies within the second if statement inside "db.query..." in the code provided below. An error message showing ERR_HTTP_HEADERS_SENT]: Cannot set headers after ...

Combine various objects into an array and ensure that any modifications are coordinated

Recently, I integrated a third-party component called <datetime-picker> into my project. This component requires a Date[] of size 2 as its v-model in order to set a range of time. However, in my existing codebase, I have been using two separate Date ...

TypeError is encountered while attempting to verify cookies

I created a function like this: const token = req.cookies['SESSION_DATA'] if (token) { ... } catch (err) { ... } However, when I try to check for a token, I receive a TypeError stating "Cannot read property of undefined." Interestingly, the same ...