当我尝试使用jsPdf从html创建pdf时出错。我的代码有什么问题吗? 提前谢谢
错误
ng:///AppModule/TemplateComponent.ngfactory.js:198 ERROR TypeError: Cannot read property 'name' of undefined
at k (vendor.bundle.js:69421)
at r (vendor.bundle.js:69421)
at vendor.bundle.js:69421
at i (vendor.bundle.js:69421)
at v (vendor.bundle.js:69421)
at x (vendor.bundle.js:69421)
at Object.e.fromHTML (vendor.bundle.js:69421)
at TemplateComponent.webpackJsonp../src/app/pages/County/template/template.component.ts.TemplateComponent.ExportToPdf (main.bundle.js:5082)
component.ts
只有当我点击按钮将html导出为pdf时才会抛出错误。
import * as jsPDF from 'jspdf';
@Component({
selector: 'app-template',
templateUrl: './template.component.html',
styleUrls: ['./template.component.scss']
})
export class TemplateComponent implements OnInit {
constructor() {
}
ExportToPdf() {
let doc = new jsPDF();
let specialElementHandlers = {
'#editor': function (element, renderer) {
return true;
}
};
let content = this.content.nativeElement;
doc.fromHTML(content.innerHTML, 15, 15, {
'width': 190,
'elementHandlers': specialElementHandlers
});
doc.save('report.pdf');
}
ngOnInit() {
this.getLocalData();
}
}