An AngularJS service that implements the HTML5 W3C saveAs() in browsers that do not natively support it
npm install angular-file-saver[![NPM version][npm-image]][npm-url]
[![Build Status][travis-image]][travis-url]
[![Dependency Status][depstat-image]][depstat-url]
> Angular File Saver is an AngularJS service that leverages
FileSaver.js and
Blob.js to implement the HTML5 W3C
saveAs() interface in browsers that do not natively support it
File dist/angular-file-saver.bundle.js contains all required dependencies and
grants access to both Blob.js and FileSaver.js polyfills via Blob andSaveAs services.
``shUsing bower:
$ bower install angular-file-saver
Basic usage
- Include ngFileSaver module into your project;
- Pass both FileSaver and Blob services as dependencies;
- Create a Blob object by
passing an array with data as the first argument and an object with set of options
as the second one: new Blob(['text'], { type: 'text/plain;charset=utf-8' });
- Invoke FileSaver.saveAs with the following arguments:
- data Blob: a Blob instance;
- filename String: a custom filename (an extension is optional);
- disableAutoBOM Boolean: (optional) Disable automatically provided Unicode text encoding hints;API
$3
A core Angular factory.
#### #saveAs(data, filename[, disableAutoBOM])
Immediately starts saving a file#### Parameters
- Blob
data: a Blob instance;
- String filename: a custom filename (an extension is optional);
- Boolean disableAutoBOM : (optional) Disable automatically provided Unicode text encoding hints;$3
An Angular factory that returns a Blob instance.$3
An Angular factory that returns a FileSaver.js polyfill.Example
JS
`js
function ExampleCtrl(FileSaver, Blob) {
var vm = this; vm.val = {
text: 'Hey ho lets go!'
};
vm.download = function(text) {
var data = new Blob([text], { type: 'text/plain;charset=utf-8' });
FileSaver.saveAs(data, 'text.txt');
};
}
angular
.module('fileSaverExample', ['ngFileSaver'])
.controller('ExampleCtrl', ['FileSaver', 'Blob', ExampleCtrl]);
`HTML
`html
``[npm-url]: https://npmjs.org/package/angular-file-saver
[npm-image]: https://img.shields.io/npm/v/angular-file-saver.svg?style=flat-square
[travis-url]: https://travis-ci.org/alferov/angular-file-saver
[travis-image]: https://img.shields.io/travis/alferov/angular-file-saver.svg?style=flat-square
[depstat-url]: https://david-dm.org/alferov/angular-file-saver
[depstat-image]: https://david-dm.org/alferov/angular-file-saver.svg?style=flat-square