[英]How to use jspdf-autotable in Angular 4?
我能够导入jsPDF,但我不能使用jspdf-autotable中的autoTable方法,不知道如何将其作为jsPDF的依赖项导入。
import { Injectable, Component } from '@angular/core';
import * as jsPDF from 'jspdf';
import { autoTable } from 'jspdf-autotable';
@Injectable()
export class PdfService {
constructor() {
}
convertJsonToPdf(columns: any, jsonData: any) {
var doc = new jsPDF('p', 'pt'); // OK, created
doc.autoTable(columns, jsonData); // Fails because autoTable is not in doc
}
}
从上面的讨论中提取,替换此行:
import { autoTable } from 'jspdf-autotable';
同
import 'jspdf-autotable';
而不是声明:
import * as jsPDF from 'jspdf';
import 'jspdf-autotable;
做得更好
import 'jspdf';
import 'jspdf-autotable;
declare let jsPDF;
这就是我解决问题的方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.