我试着用画布写一份报告。但是当我使用ng serve
启动服务器时发生了这个错误,我需要解决这个问题。那么,我如何修复这个错误呢?
在.ts
文件代码中,
import * as html2canvas from 'html2canvas';
html2canvas(document.getElementById('result-table')).then(canvas => {
let dateX = new Date();
var imgWidth = 208;
var pageHeight = 295;
var imgHeight = canvas.height * imgWidth / canvas.width;
var heightLeft = imgHeight;
const contentDataURL = canvas.toDataURL('image/png')
let pdf = new jsPDF('p', 'mm', 'a4');
var position = 30;
pdf.line(1, 1, 208, 1);
pdf.text("Results", (imgWidth / 3.3), 12)
pdf.line((imgWidth / 2.5) - 4, 15, 121, 15);
pdf.setFontSize(9);
pdf.text(`Category: ${this.dataArrr[0].cat_id}`, 5, 17)
pdf.text(`Item: ${this.dataArrr[0].item_id}`, 5, 24)
pdf.addImage(contentDataURL, 'PNG', 1, position, imgWidth, imgHeight)
pdf.setFontSize(9);
pdf.text("*This is an computer generated report!", 10, imgHeight + 40)
pdf.text(`${dateX}`, 80, imgHeight + 40)
pdf.save(`Results.pdf`);
});
}
当我使用ng serve
启动服务器时,出现如下错误:
ERROR in src/app/audition-results/audition-results.component.ts:614:5 - error TS2349: This expression is not
callable.
Type 'typeof import("D:/Audition/sisi-arundathee/node_modules/html2canvas/dist/types/index")' has no call signatures.
html2canvas(document.getElementById('result-table')).then(canvas => {
*目前,我使用的是Angular 10。
发布于 2021-01-09 02:10:44
我使用以下命令导入画布
import html2canvas from 'html2canvas';
而不是
import * as html2canvas from 'html2canvas';
现在它起作用了
https://stackoverflow.com/questions/62715825
复制相似问题