我正在尝试在Angular 2中使用ngxdatable显示导出pdf。怎么做?
答案 0 :(得分:2)
实际上有一种方法......
我一直在使用外部库来导出Angular4应用中的文档:https://github.com/eligrey/FileSaver.js/
以下是我用于提取数据的示例代码。我将此方法绑定到按钮以触发事件:
TypeScript组件:
// Notice the parameters from the service call that give me back my filtered datas
exportDatas(documentType: string) {
this.equipmentService.getExportDatas(this.detail.equipment.id, this.beginDate, this.endDate, this.frameType, documentType, this.timezoneOffset, this.translateService.currentLang)
.subscribe(result => {
const blob = new Blob([result.blob()]);
const objectUrl = URL.createObjectURL(blob);
FileSaver.saveAs(blob, 'Export.' + documentType);
});
}
模板方:
<div fxLayoutAlign="end">
<span class="label">{{'EQP_HISTORY.EXPORT'|translate}} :</span>
<button (click)="exportDatas('csv')" type="button">CSV</button>
<button (click)="exportDatas('pdf')" type="button">PDF</button>
</div>