简体   繁体   中英

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?

Check the console with this method.

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

Also there are other methods on FormData :

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM