formdata in angular 5 showing empty when console.log()

In Angular 5 html, I did the following and press the submit button. Here, in the .ts file, I want to append custom value and then want to console/print the value of the submitted form.

<form method="post" (ngSubmit)="signupFrm.form.valid && onSubmit(signupFrm)" #signupFrm="ngForm">
...
...
<button type="submit">Submit</button>
</form>

In the .ts file, I wrote:

import { NgForm }   from '@angular/forms';
....
....
onSubmit(form: NgForm){
  console.log(form.value);
  var formData = new FormData();
  formData.append('mycustom', "custom");
  for(let eachField in form.value)
  {
    formData.append(eachField,form.value[eachField]);
  }
  console.log(formData);
}

I see the console showing empty formData. Any idea?

Upvotes: 1

Views: 3034

Answers (1)

m.koch
m.koch

Reputation: 144

Check the console with this method.

console.log(formData.getAll('mycustom'));

Also there are other methods on FormData:

enter image description here

Upvotes: 2

Related Questions