Angular 中的 html2canvas - 无法调用类型缺少调用签名的表达式
html2canvas in Angular - Cannot invoke an expression whose type lacks a call signature
我正在尝试将 html2canvas 库用于 Angular 8 项目。
我还尝试通过 npm install --save @types/html2canvas
在我的项目中安装 html2canvas 类型,但它仍然无法正常工作。
模板:
<div #myform>
<form>
...
</form>
</div>
组件:
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);
});
}
}
我的意图是将表单呈现为 canvas,但应用程序抛出错误:
src/app/grid/pdf-viewer/pdf-viewer.component.ts (19,5) 中的错误:错误 TS2349:无法调用类型缺少调用签名的表达式。键入 'typeof import ("myroute")' 您不支持调用签名。
对于 Angular 8,请参阅此 link:https://github.com/niklasvh/html2canvas/issues/1896#issuecomment-506129710
基本上,您需要安装 1.0.0-rc.1 版的 html2canvas 才能工作。
已解决!谢谢:)
最后我以这种方式导入:
import html2canvas from 'html2canvas';
在 Angular 8 上遇到了同样的问题,我能够正确导入库的唯一方法是使用 require。
.
我正在尝试将 html2canvas 库用于 Angular 8 项目。
我还尝试通过 npm install --save @types/html2canvas
在我的项目中安装 html2canvas 类型,但它仍然无法正常工作。
模板:
<div #myform>
<form>
...
</form>
</div>
组件:
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);
});
}
}
我的意图是将表单呈现为 canvas,但应用程序抛出错误:
src/app/grid/pdf-viewer/pdf-viewer.component.ts (19,5) 中的错误:错误 TS2349:无法调用类型缺少调用签名的表达式。键入 'typeof import ("myroute")' 您不支持调用签名。
对于 Angular 8,请参阅此 link:https://github.com/niklasvh/html2canvas/issues/1896#issuecomment-506129710
基本上,您需要安装 1.0.0-rc.1 版的 html2canvas 才能工作。
已解决!谢谢:)
最后我以这种方式导入:
import html2canvas from 'html2canvas';
在 Angular 8 上遇到了同样的问题,我能够正确导入库的唯一方法是使用 require。