我正在使用 angular2
和 Node JS
。我已经使用 npm
安装了 jspdf 和 jspdf-autotable 两个模块。
在 angular-cli.json 文件中,我已经嵌入了这些脚本:
"scripts": [
"../node_modules/jspdf/dist/jspdf.min.js",
"../node_modules/jspdf-autotable/dist/jspdf.plugin.autotable.js"
],
在我的component.ts
文件中,我按照以下方式导入了这些文件:
import * as jsPDF from 'jspdf';
import * as autoTable from 'jspdf-autotable';
我也尝试了以下代码来导入 jspdf-autotable
import { autoTable } from 'jspdf-autotable';
import 'jspdf-autotable';
但是什么都没有起作用。
在component.ts
文件中的函数中,我使用以下示例代码:
var columns = ["ID", "Country", "Rank", "Capital"];
var data = [
[1, "Denmark", 7.526, "Copenhagen"],
[2, "Switzerland", 7.509, "Bern"],
[3, "Iceland", 7.501, "Reykjavík"],
[4, "Norway", 7.498, "Oslo"],
[5, "Finland", 7.413, "Helsinki"]
];
var doc = new jsPDF();
doc.autoTable(columns, data);
doc.output("dataurlnewwindow");
但是现在当我运行node命令启动应用程序时,在编译过程中出现以下错误:
类型“jsPDF”上不存在属性“autoTable”。
请问有人可以提供建议吗?