angular - 即使我使用了 append,FormData 对象为什么还是空的?
我尝试了以下代码:(这是我在 Angular 中的服务文件 posts.service.ts)
updatePost(id: string, title: string, content: string, image: File | string) {
let postData: Post | FormData;
console.log(id);
if(typeof(image) === 'object'){
console.log("Image is object");
const postData = new FormData();
postData.append('id',id);
postData.append('title',title);
postData.append('content', content);
postData.append('image', image, title);
console.log(postData)
} else {
console.log("In else!")
postData = { id: id, title: title, content: content, imagePath: image };
}
当我检查 console.log(postData) 时,它是空的。