Reputation: 83
I installed angular-file-saver with
bower install angular-file-saver
Then I added the dependancy in my bower.json file :
{
"name": "app",
"version": "0.0.0",
"dependencies": {
"angular": "^1.4.0",
"bootstrap": "^3.2.0",
"file-saver.js": "^1.20150507.2"
},
"devDependencies": {
"angular-mocks": "^1.4.0"
},
"appPath": "app",
"moduleName": "app",
"overrides": {
"bootstrap": {
"main": [
"less/bootstrap.less",
"dist/css/bootstrap.css",
"dist/js/bootstrap.js"
]
}
}
}
The bower.json from file-saver.js is
{
"name": "file-saver.js",
"main": "FileSaver.js",
"version": "1.20150507.2",
"homepage": "https://github.com/Teleborder/FileSaver.js",
"authors": [
"Eli Grey (http://eligrey.com)"
],
"description": "A saveAs() FileSaver implementation",
"keywords": [
"File",
"FileSaver",
"saveAs"
],
"license": "LICENSE.md",
"ignore": [
"**/.*",
"node_modules",
"bower_components",
"test",
"tests",
"demo",
"FileSaver.min.js"
]
}
Then I imported it in my controller :
controller('MainCtrl', ['$http', 'file-saver.js', function ($http, fs) {
But I get the error :
Error: "[$injector:unpr] Unknown provider: file-saver.jsProvider <- file-saver.js <- MainCtrl
https://errors.angularjs.org/1.7.8/$injector/unpr?p0=file-saver.jsProvider%20%3C-%20file-saver.js%20%3C-%20MainCtrl"
I tried other names like file-saver, FileSaver, FileSaver.js but nothing works.
Upvotes: 1
Views: 1655
Reputation: 3945
The documentation says that you need to import the ngFileSaver
module in your module and then inject FileSaver
in your component. Here's the example provided:
angular
.module('fileSaverExample', ['ngFileSaver'])
.controller('ExampleCtrl', ['FileSaver', 'Blob', ExampleCtrl]);
After that, you can invoke FileSaver.saveAs
method.
Upvotes: 1