service.ts
uploadFile(event) {
//let userForm = document.forms.namedItem('userSetting');
let formData = new FormData();
formData.append('file', document.getElementById('avatar')['files'][0]);
console.log(event, '=============>event');
console.log(document.getElementById('avatar')['files'][0], '=============>document.getElementById');
// form.append('img', document.getElementsByName('avatar')[0]['files'][0]);
console.log(formData, '================>uploadfile');
}
component.html
<div class="form-group">
<label class="col-sm-2 control-label">头像:</label>
<div class="col-sm-10">
<input type="file" name= 'avatar' id="avatar" class="form-control" placeholder="上传头像" (change)="uploadFile($event)">
</div>
</div>[why formdata is empty?][1]
表单数据看起来不行,我的代码有什么问题吗?