首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何修复这个问题,"error TS2349: this expression is not callable“in Angular

如何修复这个问题,"error TS2349: this expression is not callable“in Angular
EN

Stack Overflow用户
提问于 2020-07-03 20:51:06
回答 1查看 1.2K关注 0票数 3

我试着用画布写一份报告。但是当我使用ng serve启动服务器时发生了这个错误,我需要解决这个问题。那么,我如何修复这个错误呢?

.ts文件代码中,

代码语言:javascript
运行
复制
import * as html2canvas from 'html2canvas';
代码语言:javascript
运行
复制
 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启动服务器时,出现如下错误:

代码语言:javascript
运行
复制
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。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-01-09 02:10:44

我使用以下命令导入画布

代码语言:javascript
运行
复制
import html2canvas from 'html2canvas'; 

而不是

代码语言:javascript
运行
复制
import * as html2canvas from 'html2canvas';

现在它起作用了

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62715825

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档