我使用的是反应式表单,在表单中,我试图在发送请求之前将FormData
附加到上传文件中,我检查了表单的控制台值,它是正确的,但是当我检查网络选项卡时,应该保存FormData值的特定键变成了空的。可能的原因是什么?
以下是我的代码
// My FormGroup
this.newGarageForm = formBuilder.group({
logo: [File],
mapLocation: [''],
garageType: [],
onCallSupport: [true],
registeredOn: [moment().format('LLLL')],
jobs: [],
totalEarning: [''],
});
// ... Validations
// ...
// Appending FormData to my FormGoup
const logoData = new FormData();
logoData.append('file', selectedLogo);
logoData.append('ImageName',selectedLogo.name);
this.newGarageForm.patchValue({ logo: logoData });
// this is how I am sending my request
addGarage(garage:any){
console.log('garage: ',garage);
return this.http.post(this.baseURL+'/addNewGarage',garage);
}
在提交之前,如果我检查我的表单值是否正确,但在发送请求之后,如果我从网络选项卡中检查,我的表单的logo
属性将变为{}
转载请注明出处:http://www.hengzou.net/article/20230526/931241.html