The HttpClient.get('/') request with {observe: 'response'} is failing to retrieve some headers

Currently, I'm in the process of writing an API GET request by utilizing HttpClient.get(). Upon passing in the option to observe the response, I've encountered an issue where accessing the .keys() does not provide me with any headers apart from Content-Type.

Even though the Access-Control-Allow-Origin header has been set as a wild card (*), I am still limited to only being able to access the Content-Type header within Angular. What could be the missing piece of the puzzle here?

In my networking tab, it's clear that the header is correctly sent to my browser. Furthermore, I attempted explicitly allowing that custom header in the Access-Control-Allow-Origin settings.

Here's a snippet of my Angular App:

this.data.getClubs(1, 10, '', {clubName: 'asc'}, '').subscribe(
      dataJson => {
        console.log(dataJson.headers.keys());
}
getClubs(page: number, count: number, group: any, sorting: any, filter: any) {
    return this.http.get(this.apiUrl + `/club`, {
      params: {
        count: String(count),
        filter: String(filter),
        group: String(group),
        page: String(page),
        sorting: JSON.stringify(sorting)
      },
      headers: this.getHttpOptions().headers,
      observe: 'response'
    });
}

Please take a look at these images showcasing that the header is indeed configured to allow access: https://i.sstatic.net/Q6sk6.png https://i.sstatic.net/hAVHV.png

Your assistance on resolving this matter would be greatly appreciated!

Answer №1

The reason for this is that you must include your header name in the access-control-expose-headers parameter within the backend system.

For example, if you wish to expose a header called 'custom-header', then you should add this header to the access-control-expose-headers parameter in the backend like so:

response.set({
 "custom-header": 'value',
 "access-control-expose-headers": "custom-header"
})

Hopefully, this solution will be effective for you.

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

Developing a search feature using Angular 6 with Observable subscription for the FrontEnd application

I have a unique challenge where I need to implement a full text search in the FrontEnd due to restrictions with the API. When the frontend starts up, it fetches all data entries from the Backend and subscribes them inside a component using an async pipe. T ...

An issue has occurred with the NullInjector, specifically regarding the AppModule and Storage in Ionic 4

When attempting to launch my Ionic app using npm start, an error message appears stating "NullInjectorError: No provider for Storage!". I have already included Storage in the app.module.ts file as shown below: imports: \[ BrowserModule, IonicModule ...

Scope problem in the next() function within an Observer's callback

Recently delving into Angular 9 and incorporating Angular Material for my project. Utilizing the MatSidenavContent component which includes a method named elementScrolled that returns an Observable. I managed to successfully implement the observable witho ...

Communicating Data Between Controllers in Node.js

Within my PlantsController, I extract the Plants using the following method: function getAll() { const plants= HttpRequestPromise.get(config.ApiURL+'allPlants', config.head); return plants; } export class PlantsController { ... public ...

Directive for masking input values

I am in need of an input that adheres to the following format: [00-23]:[00-59] Due to the limitations of Angular 2.4, where the pattern directive is unavailable and external libraries like primeNG cannot be used, I have been attempting to create a direct ...

The primary origin of TypeScript is derived from the compiled JavaScript and its corresponding source map

Being new to sourcemaps and typescript, I am faced with a project that has been compiled into a single javascript file from multiple typescript files. The files available to me are: lib.js (the compiled js code of the project) lib.js.map (the source map ...

Retrieving the parent object of a nested object within a JSON data structure using TypeScript

Is there a way to programmatically retrieve the parent object from a child object? My goal is to dynamically access the value of a property that belongs to the parent of a child object. For instance, in the given JSON data, I am interested in getting the ...

Preserve component state in Angular 4 by saving it when navigating to a different component

Currently, I am faced with a challenge while developing an application using Angular. In one component, users can input data into three selectboxes and then initiate a search to find matching results. Upon clicking on a match, they are taken to another com ...

Creating a distinct Output type in Typescript to avoid any confusion between Output arguments and Input arguments

Inspired by C#, I am looking to define the following: type FunctionOutput<T> = T; // This is a basic implementation that needs improvement type Result = {result: number}; function myFun(a: number, b: number, c: FunctionOutput<Result>) { c.r ...

"Stylish form field design with outlined borders that displays a subtle hover

I am attempting to modify the background color of a mat-form-field outlined when hovering with the mouse. .mat-form-field.mat-form-field-appearance-outline.mat-form-field-outline-thick { // HOVER EFFECT background-color: $dark-blue-200; } The above ...

Error: The package name "@angular/compiler" is not valid in Npm

After successfully installing Ionic2 for a new project, I proceeded to set up a continuous integration build. However, running npm install on the build server resulted in failure with the following error: npm ERR! Windows_NT 6.2.9200 npm ERR! argv "C:&bso ...

Error in Angular 2 after transition to @types: encountering "require" name not found issue

After transitioning my project from old typings to types-publisher, I have successfully resolved most of my dependencies. However, I am consistently encountering an error that reads Cannot find name 'require'. Below is a snippet from my tsconfig. ...

Consistentize Column Titles in Uploaded Excel Spreadsheet

I have a friend who takes customer orders, and these customers are required to submit an excel sheet with specific fields such as item, description, brand, quantity, etc. However, the challenge arises when these sheets do not consistently use the same colu ...

Exploring the depths of Typescript: Navigating through intricate mapping of keys and types in dynamic

Explaining this may be a bit tricky, but I'll start with stating my objective and then elaborate on the question as clearly as possible: Note: The version of typescript doesn't matter to me, any solution would be appreciated. interface Type {} ...

What is the best location for me to update the state in order to ensure that I receive the accurate information from

Currently working on a major project to showcase my development skills in an upcoming job interview, I find myself a) lacking experience and b) short on time to make any significant code changes (like implementing Hooks). The task at hand involves retriev ...

Tips on customizing the Nuxt Route Middleware using Typescript

I am working on creating a route middleware in TypeScript that will validate the request.meta.auth field from the request object. I want to ensure this field has autocomplete options of 'user' and 'guest': export default defineNuxtRoute ...

Guide to adjusting column width in an XLSX worksheet using Angular4

I am trying to convert HTML into an XLSX sheet in Angular using SheetJS. However, I am encountering an issue where the width of each column is limited to 256 only, and I need to increase it. I have attempted to use ws[!cols] of ColInfo, but I am strugglin ...

Tips for incorporating the observer design pattern in REST APIs (Communication between front-end and back-end)

Is it possible to subscribe once to an API and receive multiple responses until I unsubscribe from that event? If so, how can this be achieved? If not, why does this approach not align with the observer pattern's guidelines? I attempted using the yie ...

When attempting to utilize the Next.js Head component in a location other than _document, the page experiences

Currently, I am in the process of integrating Next.js with Typescript and Material UI. Despite the abundance of tutorials available online for setting up Next.js with Material UI, I have encountered a commonality among them where they all provide identical ...

Ways to identify the moment a form becomes 'ready' after the component has been initialized

It seems like I might be making a mistake, as there are instances where I need to make adjustments to a Form or FormControl after a component has initialized and data has been loaded. The problem arises because the form and its controls don't seem to ...