我有一个项目,其中我们将jsPDF和autotable合并在一起,但是遇到了麻烦。
我运行的命令:
npm i jspdf --save
npm install @types/jspdf --save
npm i jspdf jspdf-autotable --save
angular.json:
"scripts": ["../node_modules/jspdf/dist/jspdf.min.js",
"../node_modules/jspdf-autotable/dist/jspdf.plugin.autotable.js"]
ts文件:
import * as jsPDF from 'jspdf';
import 'jspdf-autotable';
const doc = new jsPDF('portrait','px','a4');
doc.autotable({
head: [['Equipment_ID', 'Equipment_type_Description', 'Equipment_Description', 'Infrastructure_Name','Section_Name','Equipment_Condition','Equipment_Cost','Is_Active','Actions']],
body: this.dataSource
})
doc.save("EquipmentList");
}
错误
Property 'autotable' does not exist on type 'jsPDF'
当我这样声明时:
declare var jsPDF: any;
服务后,出现以下错误:
An unhandled exception occurred: Script file ../node_modules/jspdf/dist/jspdf.min.js does not exist.
See "C:\Users\reube\AppData\Local\Temp\ng-4iWKp5\angular-errors.log" for further details.
答案 0 :(得分:1)
要在角度5 中使用jspdf-autotable,必须通过npm安装jspdf和jspdf-autotable
npm install jspdf --save
npm install @types/jspdf --save-dev
npm install jspdf-autotable --save
另外,将jspdf和jspdf-autotable文件添加到(angular-cli.json或angular.json)中的脚本数组中,具体取决于您的角度版本
"scripts": [
"node_modules/jspdf/dist/jspdf.min.js",
"node_modules/jspdf-autotable/dist/jspdf.plugin.autotable.js"
],
并且在组件中永远不要只导入jspdf或jspdf-autotable。
忘记以下导入。
import * as jsPDF from 'jspdf'; import 'jspdf-autotable';
只需在@Component之前使用
: declare var jsPDF: any;
答案 1 :(得分:0)
请尝试删除以下代码形式angular.json:
"scripts": ["../node_modules/jspdf/dist/jspdf.min.js",
"../node_modules/jspdf-autotable/dist/jspdf.plugin.autotable.js"]