简体   繁体   中英

How to access and instantiate a javascript class from TypeScript?

I'm using jsPDF and I've added its jspdf.min.js file on the page.

How can I use it from within a typescript class? jsPDF is unknown it complains:

  btnPrintReportClick() {
        var pdf = new jsPDF();
        pdf.fromHTML($('.container').html(), 15, 15, { 'width': 170 });
        pdf.save('file_name.pdf');
    }

You'll need to use the definition file for it.

From your question I assume that you're loading jspdf simply by placing a script tag in your page, and in that case just add this triple-slash-directive to your typescript file:

/// <reference path="PATH/TO/jspdf.d.ts />

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM