Jspdf-autotable: Unable to use it in Angular 2

Created on 25 Aug 2018  路  7Comments  路  Source: simonbengtsson/jsPDF-AutoTable

Hi Sir,

I've followed your tutorial closely and did all these steps:

  1. npm install --save jspdf jspdf-autotable
  1. Add these scripts into angular.json file
    "../node_modules/jspdf/dist/jspdf.min.js",
    "../node_modules/jspdf-autotable/dist/jspdf.plugin.autotable.js"

  2. declare var jsPDF: any; in to app.component.ts rather than usual imports

However, I still get the following error
image

Here is my snippet of my codes:

image

Hope to get some help for you!

Best Regards

Most helpful comment

Can you please try this out @chinha0 ?

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

This worked for me.

All 7 comments

Hi,

I can't get any solution from the link u provided.. Is there other alternatives to it?

Can you please try this out @chinha0 ?

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

This worked for me.

@JLee21 this works well. I think it should replace the current documentation.

by the way, the second line import { autoTable } from 'jspdf-autotable'; is not necessary.

As mentioned by @jemerald the following should work. Just tested with angular 7.

import jsPDF from 'jspdf';
import 'jspdf-autotable';

let doc = new jsPDF()
doc.autoTable({html: '#table'})

@simonbengtsson I think doing import is better than the current documented method of adding scripts to angular-cli.json, would you agree?

If so, consider update the documentation?

Sounds good! Will update it for the v3 release coming in a few days.

Was this page helpful?
0 / 5 - 0 ratings