【问题标题】:How to fix this, "error TS2349: This expression is not callable" in Angular如何解决这个问题,Angular 中的“错误 TS2349:此表达式不可调用”
【发布时间】:2020-10-24 04:51:55
【问题描述】:

我正在尝试使用 Canvas 制作报告。但是当我使用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。

【问题讨论】:

    标签: angular typescript html2canvas


    【解决方案1】:

    我使用以下命令导入画布

    import html2canvas from 'html2canvas'; 
    

    而不是

    import * as html2canvas from 'html2canvas';
    

    现在它正在工作

    【讨论】:

      猜你喜欢
      • 2022-09-30
      • 2020-11-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-10-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多