我在 Angular 应用程序上使用 JSPdf,我正在尝试使用 JS 自动表插件,但我遇到了 JS 错误
异常:未捕获(承诺):TypeError:doc.autoTable 不是函数
TypeError: doc.autoTable 不是函数
我通过 npm 安装了 jspdf 和 jspdf-autotable,我确认它们在节点模块中。
我以这种方式导入了两个插件:
import * as jsPDF from 'jspdf'
import * as autoTable from 'jspdf-autotable'
这是我的代码:
private renderPdf():void{
let testcolumns = ["TestCol1", "TestCol2"];
let testrows = [["test item 1", "test item 2"]];
let doc = new jsPDF();
doc.autoTable(testcolumns, testrows);
doc.save('sample.pdf');
}
这里有什么我可能遗漏的吗?或者我可以提供更多代码来帮助确定问题吗?
谢谢!
原文由 Stu Furlong 发布,翻译遵循 CC BY-SA 4.0 许可协议
只需删除 2 第一行导入并添加以下行:
你可以 在这里 看到一个例子