typescript 在 Angular 2 项目中导入 JSZip
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/43097159/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Import JSZip in Angular 2 project
提问by Alessio
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:
在我的 Angular 2 项目中导入 JSZip 库时遇到问题。我按照以下步骤更改项目配置:
1 - Install JSZip using NPM
1 - 使用 NPM 安装 JSZip
npm install jszip --save
2 - Change systemjs.config.js as follows
2 - 更改 systemjs.config.js 如下
var map = {
...
'jszip': 'node_modules/jszip/dist/jszip.min.js'
};
3 - Import the dependency within the component that requires it
3 - 在需要它的组件中导入依赖项
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.
然后,我尝试使用主要的 JSZip 构造函数来附加一些文件,但我收到一个 Web 错误,指出该构造函数未定义。此外,我使用的 Typescript 编辑器无法找到它的定义。
Did I miss something?
我错过了什么?
Thank you.
谢谢你。
回答by Alessio
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();
回答by Yunfei Li
There is a typo and it should be:
有一个错字,应该是:
import * as JSZip from 'jszip';
let zipFile: JSZip = new JSZip();