Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular 2 - Import html2canvas

I have installed html2canvas on my angular 2 project using npm install html2canvas --save. If I now go to any file and write import * as html2canvas from 'html2canvas' it gives the error:

Cannot find module 'html2canvas'

My package file looks like this:

{
  ...
  "scripts": {
    ...
  },
  "dependencies": {
    ...
    "html2canvas": "^0.5.0-beta4",
    ...
  },
  "devDependencies": {
    ...
  }
}

The file on which I'm trying to import the html2canvas is:

import { Injectable } from '@angular/core';
import * as jsPDF from 'jspdf';
import * as html2canvas from 'html2canvas';

@Injectable ()
export class pdfGeneratorService {

  ...
}
like image 218
FlorisdG Avatar asked Feb 04 '23 17:02

FlorisdG


1 Answers

Since Angular2 uses typescript, you need to install the typescript definition files for that module.

It can be installed from @types (if it exists). If it doesn't you can create your own definition file and include it in your project.

like image 161
eko Avatar answered Feb 07 '23 17:02

eko