项目
在 GitHub 查看
alferov/angular-file-saver
关于
An AngularJS service that provides cross-browser compatibility of HTML5 saveAs() - http://alferov.github.io/angular-file-saver
网站与应用开发实测星标增长
- 24小时
- 0
- 7天
- 0
- 15天
- 0
- 1个月
- 正在收集历史
各周期内的星标净变化,周期相互重叠,并非每日新增。缺失的测量保持空白。星标代表关注度,不代表软件质量。
README.md
原文Angular File Saver
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
Dependencies
File dist/angular-file-saver.bundle.js contains all required dependencies and
grants access to both Blob.js and FileSaver.js polyfills via Blob and
SaveAs services.
Installation
# Using bower:
$ bower install angular-file-saver
# Using npm:
$ npm install angular-file-saver
Basic usage
- Include
ngFileSavermodule into your project; - Pass both
FileSaverandBlobservices 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.saveAswith the following arguments:dataBlob: a Blob instance;filenameString: a custom filename (an extension is optional);disableAutoBOMBoolean: (optional) Disable automatically provided Unicode text encoding hints;
API
FileSaver
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;
Blob(blobParts[, options]))
An Angular factory that returns a Blob instance.
SaveAs(data, filename[, disableAutoBOM])
An Angular factory that returns a FileSaver.js polyfill.
Example
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
<div class="wrapper" ng-controller="ExampleCtrl as vm">
<textarea
ng-model="vm.val.text"
name="textarea" rows="5" cols="20">
Hey ho let's go!
</textarea>
<a href="" class="btn btn-dark btn-small" ng-click="vm.download(vm.val.text)">
Download
</a>
</div>
License
MIT © Philipp Alferov
探索相关项目
加载中…