I'm currently working on integrating the html2canvas library into an Angular 8 project.
Despite trying to install the html2canvas types using
npm install --save @types/html2canvas
, I'm still facing issues with its functionality.
Here's how I set up my template:
<div #myform>
<form>
...
</form>
</div>
In the component file, I have the following code:
import { Component, OnInit, ViewChild, ElementRef } from '@angular/core';
import * as html2canvas from 'html2canvas';
@Component({
selector: 'app-pdf-viewer',
templateUrl: './pdf-viewer.component.html',
styleUrls: ['./pdf-viewer.component.scss']
})
export class PdfViewerComponent {
@ViewChild('myform', { static: false, read: ElementRef }) pdfForm: ElementRef;
constructor() {}
pdfDownload() {
html2canvas(this.pdfForm.nativeElement).then(canvas => {
const imgData = canvas.toDataURL('image/png');
document.body.appendChild(canvas);
});
}
}
My goal is to render the form as a canvas, but unfortunately, I keep encountering this error message:
ERROR in src/app/grid/pdf-viewer/pdf-viewer.component.ts (19,5): error TS2349: Can not invoke an expression whose type lacks a call signature. Type 'typeof import ("myroute")' you have not supported call signatures.