由于某种原因,fileSaver未被映射. angular2-jwt工作正常.
我做了npm install file-saver -save来获取文件保护程序,然后引用它如下(我有一个gulp任务将js文件移动到libs目录,我看到那里的文件)
在index.htmlI中已将脚本包含在src和system.config中
<script src="libs/file-saver/FileSaver.js"></script> <!-- 2. Configure SystemJS --> <script> System.config({ packages: { app: { format: 'register',defaultExtension: 'js' } },map: { "angular2-jwt": "libs/angular2-jwt/angular2-jwt.js","fileSaver":"libs/file-saver/FileSaver.js" } }); System.import('app/bootstrap') .then(null,console.error.bind(console)); </script>
component.ts
这里没有找到fileSaver
import {SaveAs} from 'fileSaver';
我得到的错误就是这个
error TS2307: Cannot find module 'fileSaver'.
知道这里有什么问题吗?
就我而言,我让它像这样工作:
原文链接:https://www.f2er.com/angularjs/142072.html的package.json:
"dependencies": { // ... all angular dependencies "file-saver": "1.3.2" },
index.html的:
<!-- all angular dependencies and other 3rd party --> <script src="node_modules/file-saver/FileSaver.js"></script>
typings.json:
// other typings needed "filesaver": "github:DefinitelyTyped/DefinitelyTyped/FileSaver/FileSaver.d.ts#d21f1bd1fd079bbc18bc88ed71d2be7f5707e33a"
用法:
var blob = new Blob([this.response],{type: 'application/zip'}); saveAs(blob,'project.zip');
您需要在运行之前执行npm安装.
就是这样,希望它有所帮助.
This won’t let you
import {SaveAs} from 'fileSaver';
nor have full code completion,but at least it works