Angular HTTP requests are failing to function properly, although they are successful when made through Postman

I am attempting to send an HTTP GET request using the specified URL:

 private materialsAPI='https://localhost:5001/api/material';

setPrice(id: any, price: any): Observable<any> {

  const url = `${this.materialsURL}/${id}/price/${price}`;


 return this.http.get<any>(url, httpOptions).pipe(
          tap(_ => this.log(`Updated material price with id=${id}`)),
          catchError(this.handleError<any>('updateMaterialPrice'))
        );
      }

However, nothing seems to be happening. When I check the network section in the browser, there is no record of the request being made. Strangely, when I try the same URL in Postman, the request goes through successfully.

Answer №1

In order for the observable to work properly, it is crucial to subscribe to it. By not calling the subscribe method on the observable, none of the actions in the chain will be executed.

Answer №2

It appears that the subscription to the get request was never completed. The request will initiate once you subscribe to it.

return this.http.get<any>(url,httpOptions).pipe(
  tap(_ => this.log(`updated material price id=${id}`)),
  catchError(this.handleError<any>('updateMaterialPrice'))
).subscribe((result) => {
  console.log('now it should work', result);
})

Check out https://angular.io/api/common/http/HttpClient#get

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

"Create dynamic tables with AngularJS using ng-repeat for column-specific rendering

I have a model called Item with the following structure: {data: String, schedule: DateTime, category: String} I want to create a report that displays the data in a table format like this: <table> <tr> <th>Time Range</th&g ...

Generating a new object from a TypeScript class using JavaScript

Currently, I am facing an issue while attempting to call a JavaScript class from TypeScript as the compiler (VS) seems to be having some trouble. The particular class in question is InfoBox, but unfortunately, I have not been able to locate a TypeScript d ...

Verify that the zip code provided in the input matches a record in the JSON data and extract the

I need to create a feature where users can input their zip code, check if it matches any of the zones in a JSON element, and then display the corresponding zone: var zones = [{ "zone": "one", "zipcodes": ["69122", "69125", "69128", "69129"] }, ...

Integrate the element offset into jQuery's offset calculations

I'm new to utilizing jQuery and currently facing a challenge in determining the correct offset for a specific div element within the body. My goal is to make this particular div stick to its position as I scroll down past its designated top offset. A ...

Displaying tooltips dynamically for newly added elements all sharing a common class in React

I'm facing an issue with the primereact tooltip component from . Everything seems to be working fine except for the target property. When I have multiple elements on a page with the same class, the tooltip works as expected. However, when I add a new ...

Connect-Domain fails to detect errors in the scenario described below:

I have chosen to implement the connect-domain module (https://github.com/baryshev/connect-domain) in order to streamline error handling within my Express application. Although it generally functions as expected, there is a peculiar issue that arises when ...

How to use patchValue with FormArray in Angular 2

, I previously inquired about reusing Angular2 model-driven form components. My objective is to develop a nested form structure where the parent component is not involved with the child components' formControlNames. Let's consider a component na ...

Display a span element using jQuery datatable to indicate that the update operation was

I have implemented inline editing using jQuery Datatables. Currently, I am trying to display a green checkmark when a record gets updated. Below is the ajax call that populates the table: $.ajax({ url: 'api/massEditorSummary.php', type: &ap ...

Steps for including a component in a loop using Angular 6

I'm working on a component that contains two input fields. The goal is to have a row pop up every time the user clicks on the add button, with all the inputs eventually being collected in an array of objects. For example, the component template looks ...

Unable to retrieve JSON data for the JavaScript object

I have been working on creating a JS object in the following manner var eleDetailsTop = new Array(); var j = 0; var id = "ele"+j; eleDetailsTop[id] = {id: id, size : "40%", sizeLabel : 12, type : "image", title : "Image& ...

Incorporate innerHTML by appending instead of overwriting

Just a quick question, can we actually add content to a <div id="whatEverId">hello one</div> by utilizing: document.getElementById("whatEverId").innerHTML += " hello two"; Is there a way to INSERT content into the div without replacing it??? ...

Implementing a Fixed Position for a Single Record in Extjs 4.2 Sortable Grid

Is there a way to allow users to sort by any column in a simple grid with sorting enabled, while ensuring that a specific record is always displayed at the last position (based on its ID)? I am working with ExtJS 4.2.2. ...

Issues with style not loading properly within innerHTML in Angular2

Currently, I am in the process of developing a page using Angular2/4 that includes a left navigation bar. To achieve reusability, I have separated this left menu into its own component and nested it within the main component. The objective is to utilize th ...

Converting an MVC form into JSON using Jquery

I am encountering an issue with serializing my MVC form to JSON using JQuery and then deserializing some values, like the input field value, on the backend in C#. I have tried to serialize it in JSON without success. Can someone please assist me with this ...

To toggle between two scope variables within a view when one is not defined

In my application, I am utilizing two scope variables: $scope.banner and $scope.defaultBanner. The banner is fetched using a service, but in cases where the banner file does not exist, the variable will be empty as the service returns nothing. My goal is ...

animation of several rows in a table with ng-animate is not feasible

I'm working on highlighting items when they appear in a table. There might be multiple items appearing simultaneously, but it seems like ng-animate is not handling this situation correctly. In the provided example below, you can observe that the div ...

Filter items by nested properties in ngRepeat

Is it possible to filter a complex object with nested properties using the ng-repeat filter? Can we achieve this filtering with the ng-repeat filter provided out of the box? Data { Name: 'John Smith', Manager: { id: 123, Name: &a ...

ui-grid row size set to automatically adjust using rowHeight : 'auto'

Has anyone else experienced this strange behavior with ui-grid? When I set the rowHeight to auto, each cell in the same row ends up with different heights. One of the cells contains multiline data, which seems to be causing issues for ui-grid. I've ev ...

Determine the frequency of each element in an array and arrange them in ascending order

In my quest to locate occurrences of numbers within an array, I aimed to display the numbers and their respective frequencies in ascending order. Here is what I was trying to achieve: let arr = [9,-10,2,9,6,1,2,10,-8,-10,2,9,6,1]; // {'-10': 2, ...

Is there a way to prevent this JavaScript code from deleting the initial row of my table?

Looking at the code provided, it's evident that creating and deleting new rows is a straightforward process. However, there seems to be an issue where the default/origin/first row (A-T) gets deleted along with the rest of the rows. The main requiremen ...