在Angular 2项目中导入JSZip [英] Import JSZip in Angular 2 project
问题描述
在Angular 2项目中导入JSZip库时遇到麻烦. 我按照以下步骤操作,以更改项目配置:
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-使用NPM安装JSZip
1 - Install JSZip using NPM
npm install jszip --save
2-如下更改systemjs.config.js
2 - Change systemjs.config.js as follows
var map = {
...
'jszip': 'node_modules/jszip/dist/jszip.min.js'
};
3-将依赖项导入需要它的组件中
3 - Import the dependency within the component that requires it
import JSZip from 'jszip';
然后,我尝试使用主要的JSZip构造函数附加一些文件,但出现网络错误,指出未定义构造函数.此外,我使用的Typescript编辑器无法找到它的定义.
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.
我错过了什么吗?
谢谢.
推荐答案
对于那些想知道它如何结束的人来说,问题出在导入上. 以下是正确的导入:
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';
然后,其用法如下:
let zipFile: JSZip = new JSZip();
这篇关于在Angular 2项目中导入JSZip的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!