1

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?

1 Answers1

2

Check the console with this method.

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

Also there are other methods on FormData:

enter image description here

m.koch
  • 144
  • 2
  • @NiladriBanerjee-Uttarpara check out this topic and first answer https://stackoverflow.com/questions/17066875/how-to-inspect-formdata – m.koch Jan 04 '19 at 14:49