Angular 文件保护程序未知提供者
Angular file-saver unknown provider
我用
安装了angular-file-saver
bower install angular-file-saver
然后我在 bower.json 文件中添加了依赖项:
{
"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"
]
}
}
}
来自文件-saver.js的bower.json是
{
"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"
]
}
然后我将它导入到我的控制器中:
controller('MainCtrl', ['$http', 'file-saver.js', function ($http, fs) {
但我收到错误消息:
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"
我尝试了其他名称,例如 file-saver、FileSaver、FileSaver.js,但没有任何效果。
文档说你需要在你的模块中导入ngFileSaver
模块,然后在你的组件中注入FileSaver
。这是提供的示例:
angular
.module('fileSaverExample', ['ngFileSaver'])
.controller('ExampleCtrl', ['FileSaver', 'Blob', ExampleCtrl]);
之后,您可以调用 FileSaver.saveAs
方法。
我用
安装了angular-file-saverbower install angular-file-saver
然后我在 bower.json 文件中添加了依赖项:
{
"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"
]
}
}
}
来自文件-saver.js的bower.json是
{
"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"
]
}
然后我将它导入到我的控制器中:
controller('MainCtrl', ['$http', 'file-saver.js', function ($http, fs) {
但我收到错误消息:
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"
我尝试了其他名称,例如 file-saver、FileSaver、FileSaver.js,但没有任何效果。
文档说你需要在你的模块中导入ngFileSaver
模块,然后在你的组件中注入FileSaver
。这是提供的示例:
angular
.module('fileSaverExample', ['ngFileSaver'])
.controller('ExampleCtrl', ['FileSaver', 'Blob', ExampleCtrl]);
之后,您可以调用 FileSaver.saveAs
方法。