angular-file-saver
Version:
An AngularJS service that implements the HTML5 W3C saveAs() in browsers that do not natively support it
22 lines (16 loc) • 542 B
JavaScript
;
var angular = require('angular');
require('../../../src/angular-file-saver-bundle.module');
function DownloadText(FileSaver, Blob, $timeout) {
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' });
$timeout(FileSaver.saveAs.bind(FileSaver, data, 'text.txt'), 100);
};
}
angular
.module('fileSaverExample', ['ngFileSaver'])
.controller('DownloadText', ['FileSaver', 'Blob', '$timeout', DownloadText]);