Jga*_*ona 5 types html2canvas typescript angular
我正在尝试将html2canvas库用于Angular 8项目。
我也尝试通过在项目中安装html2canvas类型,npm install --save @types/html2canvas
但仍然无法正常工作。
模板:
<div #myform>
<form>
...
</form>
</div>
Run Code Online (Sandbox Code Playgroud)
零件:
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);
});
}
}
Run Code Online (Sandbox Code Playgroud)
我的意图是将表单呈现为画布,但是应用程序引发错误:
src / app / grid / pdf-viewer / pdf-viewer.component.ts中的错误(19,5):错误TS2349:无法调用类型缺少调用签名的表达式。输入'typeof import(“ myroute”)',表示您不支持呼叫签名。
解决了!谢谢 :)
最终我以这种方式导入:
import html2canvas from 'html2canvas';
Run Code Online (Sandbox Code Playgroud)
对于Angular 8,请访问以下链接:https : //github.com/niklasvh/html2canvas/issues/1896#issuecomment-506129710
基本上,您需要安装html2canvas的1.0.0-rc.1版本才能正常工作。
归档时间: |
|
查看次数: |
1725 次 |
最近记录: |