如何修复 Angular 中的“错误 TS2349:此表达式不可调用”

Tha*_*han 6 html2canvas typescript angular

我试图使用 Canvas 制作报告。ng serve 但是当我使用“我需要修复此问题”启动服务器时发生此错误。那么,我该如何修复这个错误呢?

在文件代码.ts如下,

import * as html2canvas from 'html2canvas';
Run Code Online (Sandbox Code Playgroud)
 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`);
    });
  }
Run Code Online (Sandbox Code Playgroud)

当我使用 启动服务器时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 => {
Run Code Online (Sandbox Code Playgroud)

*目前,我使用的是 Angular 10。

Tha*_*han 3

我使用以下命令导入画布

import html2canvas from 'html2canvas'; 
Run Code Online (Sandbox Code Playgroud)

代替

import * as html2canvas from 'html2canvas';
Run Code Online (Sandbox Code Playgroud)

现在它正在工作