I'm dealing with an API that requires the country code in the header along with an authorization token and Bearer. In my component file, I am able to fetch the value from a mat-select dropdown. However, the setting for the API header and token is done in the service file. Can someone assist me in passing the mat-select value from the component to the service file?
Currently, I have hardcoded the country value as 'au', but I want it to be set dynamically based on the mat-select dropdown value.
Below is the code snippet to fetch the mat-select value in the Component File:
onCountrySelection() {
console.log(this.countryValue);
sessionStorage.setItem('countryCode', this.countryValue);
}
Here's how the API is defined in the Service Class File:
uploadConfig(templateName, JsonBody) {
const header = new HttpHeaders().set(
'Authorization',
'Bearer ' + sessionStorage.getItem('token'),
).set(
'country',
'au'
);
return this.httpClient.post(
this.localUrl + '/pattern/' + templateName + '/flow', JsonBody,
{ headers: header }
);
}