2017-09-20 58 views
1

我能够导入jsPDF,但是我无法使用jspdf-autotable中的autoTable方法,不知道如何将它作为jsPDF的依赖项导入。如何在Angular 4中使用jspdf-autotable?

import { Injectable, Component } from '@angular/core'; 

import * as jsPDF from 'jspdf'; 
import { autoTable } from 'jspdf-autotable'; 

@Injectable() 
export class PdfService { 

    constructor() { 

    } 

    convertJsonToPdf(columns: any, jsonData: any) { 
     var doc = new jsPDF('p', 'pt'); // OK, created 
     doc.autoTable(columns, jsonData); // Fails because autoTable is not in doc 
    } 
} 
+1

尝试更换从 'jspdf-autotable' 这行'进口{autoTable};'与' import'jspdf-autotable';'; –

+0

@SimonBengtsson它的工作,谢谢。 – user1916077

回答

3

从上面的讨论中提取,替换这一行:

import { autoTable } from 'jspdf-autotable'; 

import 'jspdf-autotable'; 
+0

angular2怎么样?导入'jspdf-autotable';或从'jspdf-autotable'导入{autoTable};没有任何工作 – Deep

+0

'import'jspdf-autotable';'应该工作。如果它不适合你,请随时用更多信息写一个新问题。 –

+0

https://stackoverflow.com/questions/47344349/property-autotable-does-not-exist-on-type-jspdf这是确切的问题 – Deep

相关问题