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 Angular 4
?
If possible, then how?
Right-click on the file or folder.Select “Compressed (zipped) folder”. To place multiple files into a zip folder, select all of the files while hitting the Ctrl button. Then, right-click on one of the files, move your cursor over the “Send to” option and select “Compressed (zipped) folder”.
A ZIP file is a container for other files. ZIP files compress their contents, which reduces downloading time. To download a ZIP file, click on a link to it; this will prompt your browswer to ask you if you would like to open or save the file.
You can use any JS library in Angular. So for example you can use JSzip and then just:
import * as JSZip from 'jszip';
And now you will have access to this library methods. You can read more about using pure JS libs in angular. There is quite a lot of information about it and even clear instructions how to do it and use properly. I think it will be better if you dive in into this subject more instead of getting clear instruction step by step how to do it. You will learn more and if you will have such a problem in future you will solve it easily. I hope this suggestion will help you.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With