Is it possible to generate zip file and download in Angular 4?

前端 未结 2 1188
南旧
南旧 2020-12-11 11:36

I am beginner in Angular 4. I have refer lots of Links for generate Zip file but I can not get proper solution.
Is it possible to generate Zip file in Angu

2条回答
  •  离开以前
    2020-12-11 12:13

    Install library

    $ npm install --save npm install jszip
    

    In a file tsconfig.json

    {"compilerOptions": {"paths": {
      "jszip": ["../node_modules/jszip/dist/jszip.min.js"]
    }}}
    

    In a file demo.component.ts

    import { saveAs, encodeBase64 } from '@progress/kendo-file-saver';
    import * as JSZip from 'jszip';
    

    Function on demo.component.ts

    downloadFileExample() {
      const jszip = new JSZip();
      jszip.file('Hello.txt', 'Hello World\n');
    
      jszip.generateAsync({ type: 'blob' }).then(function(content) {
        // see FileSaver.js
        saveAs(content, 'example.zip');
      });
    }
    

    This example is with Angular 6.

提交回复
热议问题