使用ng-zorro里面组件Upload上传
<nz-upload [nzCustomRequest]="customReq" [nzShowUploadList]='false'>
<button nz-button><i nz-icon nzType="upload"></i><span>上传</span> </button>
</nz-upload>
需要引入 import { UploadXHRArgs } from 'ng-zorro-antd';
其中nzCustomRequest
改变默认上传行为,自定义上传;
[nzShowUploadList] 是否展示 uploadList,默认值是true;不想展示设置为false;
customReq = (item: UploadXHRArgs) => {
const formData = new FormData();
formData.append('file', item.file as any);
this.api.post('----',formData).then(res=>{
this.message.success('导入成功');
}).catch((error) => {
this.message.error(error.message);
})
};
'---’代表请求的接口;