Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.6k views
in Technique[技术] by (71.8m points)

typescript - Import JSZip in Angular 2 project

I am having troubles while importing the JSZip library in my Angular 2 project. I followed the following steps in order to change the project configuration:

1 - Install JSZip using NPM

npm install jszip --save

2 - Change systemjs.config.js as follows

var map = {
    ...
    'jszip':                      'node_modules/jszip/dist/jszip.min.js'
};

3 - Import the dependency within the component that requires it

import JSZip from 'jszip';

Then, I tried using the main JSZip constructor to attach some files, but I am getting a web error stating that the constructor is not defined. Besides, the Typescript editor I am using is not able to find the definition for it.

Did I miss something?

Thank you.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

For those who want to know how it ended, the problem was in the import. The following is the correct import:

import * as JSZip from 'jszip';

Then, it is used as follows:

let zipFile: JSZip = new JSZip();

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...