Tharindu Lakshan
Tharindu Lakshan

Reputation: 6186

How to fix this, "error TS2349: This expression is not callable" in Angular

I was trying to make a report using Canvas. but this error has occurred when I start the server using ng serve I need to fix this issue. so, How can I fix this error?

In code of .ts file as follows,

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`);
    });
  }

when I start the server using ng serve, an error occurred as follows,


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 => {

*Currently, I'm using Angular 10.

Upvotes: 6

Views: 3799

Answers (1)

Tharindu Lakshan
Tharindu Lakshan

Reputation: 6186

I used the following command to import canvas

import html2canvas from 'html2canvas'; 

instead of

import * as html2canvas from 'html2canvas';

and now it's working

Upvotes: 3

Related Questions