1. file saver
- 功能:下载文件到本地
npm install file-saver --save
npm install @type/file-saver --save
用的时候在ts里面导入
import * as FileSaver from 'file-saver';
... ...
wrapStr = 'xxxsdfasdfasdfsdfsdf';
const chdlFileName = 'sun.csv';
const blob = new Blob([wrapStr], {});
FileSaver.saveAs(blob, chdlFileName);
2. ng2-file-upload
- 功能: 上传本地文件
npm install ng2-file-upload --save
在 app.module.ts
文件中引入模块
import { FileUploadModule } from 'ng2-file-upload';
@NgModule({
... ...
imports: [
... ...
FileUploadModule
],
... ...
})
然后在对应的Component中,引入FileUploader
import { FileUploader } from 'ng2-file-upload';
3. jszip
- 功能:打包文件
npm install jszip
import * as JSZip from 'jszip';
const arr = [
{name: 'file1', fileContent: 'hello'},
{name: 'file2', fileContent: 'world'}
];
... ...
zipDownload(verilogArr) {
const zip = new JSZip();
const folder = zip.folder();
for (let i = 0; i < arr.length; i ++) {
const filename = arr[i].name + '.v';
folder.file(filename, verilogArr[i].fileContent);
}
zip.generateAsync({type: 'blob'}).then(
(content) => {
// 把打包好的文件下载下来,依赖 file saver
FileSaver.saveAs(content, "verilogZip.zip");
}
);
}
4. Split.js
Split.js 是一个轻量级的 JavaScript 工具,用于创建可调整的分割视图或者窗格。
npm install split.js
5. angular-split
https://bertrandg.github.io/angular-split/#/documentation
Error
-
Module not found: Error: Can't resolve 'stream' in xxx
解决方法:安装stream,npm i stream --save