2017-06-23 78 views
1

我使用JSPdf上的角應用程序,我試圖用JS autotable插件,但我遇到的JS錯誤jsPDF AutoTable - autoTable不是一個函數

EXCEPTION: Uncaught (in promise): TypeError: doc.autoTable is not a function

TypeError: doc.autoTable is not a function

我有通過npm安裝jspdf和jspdf-autotable,我確認它們在節點模塊中。

我已經導入這兩個插件是這樣的:

import * as jsPDF from 'jspdf' 
import * as autoTable from 'jspdf-autotable' 

這裏是我的代碼:

private renderPdf():void{ 
    let testcolumns = ["TestCol1", "TestCol2"]; 
    let testrows = [["test item 1", "test item 2"]]; 
    let doc = new jsPDF(); 
    doc.autoTable(testcolumns, testrows); 
    doc.save('sample.pdf'); 
} 

有什麼我可以在這裏失去了以上的代碼,我可以提供幫助確定問題?

謝謝!

回答

2

只要刪除進口的2第一行,並添加以下行:

var jsPDF = require('jspdf'); 
require('jspdf-autotable'); 

你可以看到一個例子here

+0

天哪 - 我不能感謝你纔好! –

相關問題