I am currently learning angular and facing a small problem that I'm unsure how to solve. My module looks like this:
const hostHandler = setContext((operation: any, context: any) => ({
headers: {
...context?.headers,
'X-Location-Hostname': hostname,
'X-Location-Origin': origin,
'X-App-Mode': test,
'X-Language': get query param here,
},
}));
The issue arises when I want to retrieve the URL parameter when someone enters "?country="UK"". In all the examples I've seen, they use something similar to this:
export class MyComponent {
constructor(
private route: ActivatedRoute
) {}
ngOnInit() {
const firstParam: string = this.route.snapshot.queryParamMap.get('country');
}
}
Whenever I try to add this to my module, I encounter an error stating that I need a decorator. Is there a way for me to fetch the query parameter and send it along with the headers?
I attempted to obtain the query parameter in the app component and store it like so:
public ngOnInit() {
this.store.dispatch(new GetNavigation());
this.route.queryParams.subscribe(params => {
if(params["country"])
{
localStorage.setItem('countryParam', params["country"]);
}
})
}
While this method works, the issue is that part of the code in the module executes before this, resulting in the correct value being retrieved from storage only upon page refresh when the storage is populated with the country parameter. Any advice on how to tackle this dilemma would be greatly appreciated.