You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
File `dist/angular-file-saver.bundle.js` contains all required dependencies and
15
+
grants access to both `Blob.js` and `FileSaver.js` polyfills via `Blob` and
16
+
`SaveAs` services.
17
+
18
+
## Installationand grants access to both `Blob.js` and `FileSaver.js`
19
+
polyfills via `Blob` and `SaveAs` services
15
20
Using bower:
16
21
```
17
22
$ bower install angular-file-saver
@@ -21,20 +26,20 @@ Using npm:
21
26
$ npm install angular-file-saver
22
27
```
23
28
24
-
`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 (include `ngFileSaver` module as a dependency first).
25
-
26
29
## Basic usage
27
30
- Include the `ngFileSaver` module to your project;
28
-
- Pass `FileSaver` service as a dependency;
29
-
- Invoke `FileSaver.saveAs` and pass an object with the following set of options:
30
-
-`data` - data, represented as an array or a [Blob object](https://developer.mozilla.org/en/docs/Web/API/Blob);
31
+
- Pass both `FileSaver` and `Blob` services as dependencies;
32
+
- Create a [Blob object](https://developer.mozilla.org/en/docs/Web/API/Blob)
33
+
passing an array with data as a first argument and an object with set of options
34
+
as the second one: `new Blob(['text'], { type: 'text/plain;charset=utf-8' })`;
35
+
- Invoke `FileSaver.saveAs` with the following arguments:
36
+
-`data` - a Blob object instance;
31
37
-`filename`;
32
-
-`options` - a set of options for the [Blob constructor](https://developer.mozilla.org/en/docs/Web/API/Blob)(optional attribute);
33
38
34
39
## Example
35
40
**JS**
36
41
```
37
-
function ExampleCtrl(FileSaver) {
42
+
function ExampleCtrl(FileSaver, Blob) {
38
43
var vm = this;
39
44
40
45
vm.val = {
@@ -43,12 +48,11 @@ function ExampleCtrl(FileSaver) {
43
48
44
49
vm.download = function(text) {
45
50
51
+
var data = new Blob(['text'], { type: 'text/plain;charset=utf-8' });
52
+
46
53
var config = {
47
-
data: [text],
48
-
filename: 'textfile.txt',
49
-
options: {
50
-
type: 'text/plain;charset=utf-8'
51
-
}
54
+
data: data,
55
+
filename: 'textfile.txt'
52
56
};
53
57
54
58
FileSaver.saveAs(config);
@@ -57,7 +61,7 @@ function ExampleCtrl(FileSaver) {
<p>File <code>dist/angular-file-saver.bundle.js</code> contains all required dependencies and
37
+
grants access to both <code>Blob.js</code> and <code>FileSaver.js</code> polyfills via <code>Blob</code> and
38
+
<code>SaveAs</code> services.</p>
39
+
<h2id="installationand-grants-access-to-both-blob-js-and-filesaver-js-">Installationand grants access to both <code>Blob.js</code> and <code>FileSaver.js</code></h2>
40
+
<p>polyfills via <code>Blob</code> and <code>SaveAs</code> services
41
+
Using bower:</p>
38
42
<pre><code>$ bower install angular-file-saver
39
43
</code></pre><p>Using npm:</p>
40
44
<pre><code>$ npm install angular-file-saver
41
-
</code></pre><p><code>dist/angular-file-saver.bundle.js</code> contains all required dependencies and grants access to both <code>Blob.js</code> and <code>FileSaver.js</code> polyfills via <code>Blob</code> and <code>SaveAs</code> services (include <code>ngFileSaver</code> module as a dependency first).</p>
42
-
<h2id="basic-usage">Basic usage</h2>
45
+
</code></pre><h2id="basic-usage">Basic usage</h2>
43
46
<ul>
44
47
<li>Include the <code>ngFileSaver</code> module to your project;</li>
45
-
<li>Pass <code>FileSaver</code> service as a dependency;</li>
46
-
<li>Invoke <code>FileSaver.saveAs</code> and pass an object with the following set of options:<ul>
47
-
<li><code>data</code> - data, represented as an array or a <ahref="https://developer.mozilla.org/en/docs/Web/API/Blob">Blob object</a>;</li>
48
+
<li>Pass both <code>FileSaver</code> and <code>Blob</code> services as dependencies;</li>
49
+
<li>Create a <ahref="https://developer.mozilla.org/en/docs/Web/API/Blob">Blob object</a>
50
+
passing an array with data as a first argument and an object with set of options
51
+
as the second one: <code>new Blob(['text'], { type: 'text/plain;charset=utf-8' })</code>;</li>
52
+
<li>Invoke <code>FileSaver.saveAs</code> with the following arguments:<ul>
53
+
<li><code>data</code> - a Blob object instance;</li>
48
54
<li><code>filename</code>;</li>
49
-
<li><code>options</code> - a set of options for the <ahref="https://developer.mozilla.org/en/docs/Web/API/Blob">Blob constructor</a>(optional attribute);</li>
0 commit comments