Reputation: 2329
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
Reputation: 144
Check the console with this method.
console.log(formData.getAll('mycustom'));
Also there are other methods on FormData:
Upvotes: 2