The HttpPut request code format is malfunctioning, although it is effective for another request

I'm struggling with a HTTPPUT request that just won't get called. Strangely enough, I have a similar put request that works perfectly fine for another tab even though both pages are practically identical. I've exhausted all options and can't seem to figure out what's going wrong.

Here is the code snippet from my controller:

   [HttpPut]
        [Route("updateAllocations({type})")]
        public IHttpActionResult UpdateAllocations(string type, T_LOC entity)
        {
            System.Diagnostics.Debug.WriteLine("inside");
            _allocationsService.UpdateAllocations(type,entity);
            return Ok();
        }

This is what I have in my interface:

using OTPS.Core.Objects;
using System.Collections.Generic;
using OTPS.Core.Models;
namespace OTPS.Core.Interfaces
{
    public interface IAllocationsService
    {

        void UpdateAllocations(string type,  T_LOC entity);
    }
}

And this is the corresponding service implementation:

  public void UpdateAllocations(string type, T_LOC entity)
        {
            System.Diagnostics.Debug.WriteLine("inside");
        }

On the client side, I have the following function defined:

 public updateAllocation(type: string , entity) {
        console.log("sdfsdf")
        console.log(`${this.baseUrl}/api/allocations/updateAllocations(${type})`)
        return this.http.put(`${this.baseUrl}/api/allocations/updateAllocations({type})`, entity, { headers: this.headers, withCredentials: true })
            .pipe(catchError((error: Error) => {
                console.log("sdfasd111111sdf")
                return this.errorService.handleError(error);
            }));
    }

Despite setting up everything correctly, the put request on the server side doesn't seem to be triggered as expected before moving on to any further logic.

Answer №1

To ensure proper functionality, remember to subscribe to the service method within your component:

this.myService.updateAllocation(type, entity).subscribe( response => {
// perform actions with response

});

Remember, you must include subscribe() or nothing will happen. Simply calling the service method does not trigger the PUT/DELETE/POST/GET request.

Always remember to subscribe!

An HttpClient method will only initiate its HTTP request once you invoke subscribe() on the observable received from that method. This rule applies to all methods in HttpClient.

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

Page_Load method does not get invoked during a POST request

After creating a web page with jquery ajax calls, I realized that the Page_Load method is not triggered for a jquery ajax POST request. However, I require the Page_Load call to access the name of the logged-in user and store it in the database along with t ...

Enhancing performance with React.memo and TypeScript

I am currently developing a react native application. I am using the Item component within a flatlist to display data, however, I encountered an error in the editor regarding the second parameter of React.memo: The error message reads: 'Type 'bo ...

What is the process for personalizing the appearance in cdk drag and drop mode?

I have created a small list of characters that are draggable using Cdk Drag Drop. Everything is working well so far! Now, I want to customize the style of the draggable items. I came across .cdk-drag-preview class for styling, which also includes box-shado ...

What is the best way to extract a property if it may be undefined?

Can anyone help with this TypeScript error I'm encountering during build time? Any suggestions would be appreciated. Error Message: TypeError: Cannot destructure property 'site' of '(intermediate value)' as it is undefined. export ...

Context for Apollo server has not been defined

Following the upgrade to Apollo v4 and migration guide, my project was functioning properly. However, the context is now undefined. const { url } = await startStandaloneServer(server, { listen: { port: 3000 }, context: async ({ req }) => { try ...

What is the best way to specify parameter names and types for a TypeScript function that can take either one or two arguments?

Looking to create a function with two different calling options: function visit(url: string, options: Partial<VisitOptions>): void function visit(options: Partial<VisitOptions> & {url:string}): void I'm exploring the most effective w ...

Using a Typescript enum as a parameter type can lead to accepting incorrect values

When working with TypeScript, I have defined an enum, and now I want to create a function that accepts a parameter whose value is one of the enum's values. However, TypeScript does not validate the value against the enum, allowing values outside of th ...

The issue encountered in Cocos Creator 3.8 is the error message "FBInstant games SDK throws an error stating 'FBInstant' name cannot be found.ts(2304)"

Encountering the error "Cannot find name 'FBInstant'.ts(2304)" while using FBInstant games SDK in Cocos Creator 3.8. Attempting to resolve by following a guide: The guide states: "Cocos Creator simplifies the process for users: ...

Creating dynamic HTML with Angular 2 using property binding

After retrieving an HTML string from the database, I came across html='<span>{{name}}</span>' where 'name' is a component property. I am looking to display this string in HTML while maintaining the name binding. I have expl ...

Which delivers better performance: HTTP request from server or client?

Considering the optimal performance, is there a difference in using Angular's HTTP request within a MEAN-stack environment compared to utilizing Request.js or similar for server requests? ...

Protected link between ASP.NET and Flash

On pageA, there is a flash player that loads and plays content. The rtmp URL that the player uses is stored in a separate .aspx file that verifies a session created on pageA. Are there any alternative methods or improved ways to prevent users from accessi ...

How to fill an HTML template using ngFor without using a JSON array

Is there a way to fill the HTML with basic JSON like below: { "id": 34, "name": "Tip 33", "description": "Tip description 33", "created_at": "2018-01-26 18:59:19", "updated_at": "2018-01-26 18:59:19" } The code i tried using was: < ...

Salesforce sales information

I am currently working on an ASP.NET application and looking to incorporate Salesforce CRM using APEX. I have started writing the APEX code in the Salesforce developers area, but I'm unsure if I am approaching this integration in the correct way. Can ...

Effective Management of Uploaded Files

I am currently working on an Angular2 application that interacts with a .NET WebApi to generate text files. Once these files are created, the goal is for users to be able to download them from the application. I am seeking guidance on the best practices ...

What could be causing React to generate an error when attempting to utilize my custom hook to retrieve data from Firebase using context?

Currently, I am restructuring my code to improve organization by moving data fetching to custom hooks instead of within the component file. However, I am encountering issues with the hook not functioning properly when used in conjunction with my context. ...

Adding a Script in ASP .NET: What's the best way to do it?

I am encountering an issue with adding a dynamic script in ASP .NET I am trying to insert the script in scriptText within ASP:ScriptManager, but it doesn't seem to work when I run my application. Can someone assist me with this? This application is ...

"Unable to convert object into a primitive value" error message appears on Internet Explorer

Currently working on a webpage using Angular 7. The code is functioning perfectly in Chrome, however, I am facing an Exception error while running it in IE: An issue arises: Can't convert object to primitive value (polyfills.ts) The source of the er ...

Steps to assign a JSON file to an array within an object in Angular

What is the best way to assign a JSON file to an array within my "Client" object? I currently have a JSON file named Clients.json with the following structure: { "clients": [ { "firstName": "nameA", "lastName": "lastA", "doctorsNam ...

Tips for displaying HTML content from a JSON web template

Currently, I am working with a JSON web template that consists of nested elements. My goal is to render HTML based on the content of this JSON web template. I attempted using ngx-schema-form, however my JSON does not contain properties variables. I also t ...

"Enhancing the functionality of @angular/fire by transitioning from version 6.x to 7.x

I need to update my app dependencies and code from @angular/fire 6.x to 7.1.0-rc4 in order to access a feature that is not available in the 7.0.x version. I made the necessary changes in my package.json as follows: "@angular/fire": "~7.1.0-r ...