如何在Angular 5中上传Excel文件

时间:2018-08-23 10:01:39

标签: javascript angular5

这是我的html代码,我创建了一个表单并尝试上传excel文件,该文件将读取excel内容并调用其余的api

<form [formGroup]="myform" (ngSubmit)="onSubmit()">
<div class="form-group">
<input type="file" id="avatar" (change)="onFileChange($event)" #fileInput>
<button type="button" class="btn btn-sm btn-default" (click)="clearFile()">clear file</button>
</div>
<button type="submit" class="btn btn-primary">Upload <i class="fa fa-spinner fa-spin fa-fw"></i></button>
</form>

Here is my ts code

private prepareSave(): any {
let input = new FormData();
input.append('name', this.myform.get('name').value);
input.append('avatar', this.myform.get('avatar').value);
//console.log("this is ==> ", this.myform.get('name').value , " === ", this.myform.get('avatar').value);
var options = { content: input };
return this.myform.get('avatar').value;
//return input;
}

onSubmit() {
const formModel = this.prepareSave();
this.loading = true;
let fData = new FormData();
fData.append('data', this.logId);
fData.append('data', AppComponent.responseUserData["applogin"]["role"]);
this.configs.uploadExcel(fData, formModel).subscribe(
data => console.log('success'),error => console.log(error)
)   
}  

有些不起作用,请帮助

0 个答案:

没有答案