app.module.ts
getHttpParams = () => {
const httpParamsInstance = new HttpParams();
console.log(this.userForm.controls)
Object.keys(this.userForm.controls).forEach(key => {
console.log(this.userForm.get(key).value)
const value = this.userForm.get(key).value;
if (value){
console.log('Adding key and value' + httpParamsInstance.append(key, value)) ==> Correct value displayed
httpParamsInstance.append(key, value); ==> However, when checking the HttpParams map, it returns null
console.log(httpParamsInstance)
}
});
return httpParamsInstance;
}
onSubmit() {
this.router.queryParams.subscribe(params => {
let options = { params: this.getHttpParams() }
console.log(options)
this.http.get<User>(`${this.serverUrl}`, options).subscribe(
response => {
this.user = response
console.log(response)
}
),
console.log(params);
})
}
Although getHttpParams function retrieves the correct values, the httpParams.append
method is returning null within the HttpParams Map. Any suggestions on how to resolve this issue? Thank you!