I am trying to pass values to formData from a form in my view, but when I am passing my parameters, it is showing undefined.
// Initialize Params Object
let myFormData = new FormData();
// Begin assigning parameters
const username = myFormData.append('myUsername', this.registerForm.value.firstname);
const email = myFormData.append('myEmail', this.registerForm.value.email);
//post request
return this.http.post('http://localhost:81/save.php/', myFormData).subscribe((res: Response) => {
console.log(res);
},
(err) =>{
this.indexedDbService
.addUser(username,email) // undefined , undefined
.then(this.backgroundSync)
.catch(console.log);
// this.backgroundSync();
})
}
However, if I try passing a hard-coded JSON object, it is taking properly.
How can I pass data from myFormData into the parameters of addUser properly?