我尝试使用ng-file-upload指令(https://github.com/danialfarid/ng-file-upload)将文件上传功能添加到我的项目中,但一直收到以下错误:
Error: [$injector:unpr] http://errors.angularjs.org/1.4.6/$injector/unpr?p0=UploadProvider%20%3C-%20Upload%20%3C-%20ExperimentController
at Error (native)
at http://localhost:8000/static/editor/js/angular.min.js:6:416
at http://localhost:8000/static/editor/js/angular.min.js:40:409
at Object.d [as get] (http://localhost:8000/static/editor/js/angular.min.js:38:394)
at http://localhost:8000/static/editor/js/angular.min.js:40:483
at d (http://localhost:8000/static/editor/js/angular.min.js:38:394)
at e (http://localhost:8000/static/editor/js/angular.min.js:39:161)
at Object.instantiate (http://localhost:8000/static/editor/js/angular.min.js:39:310)
at http://localhost:8000/static/editor/js/angular.min.js:80:313
at A.link (http://localhost:8000/static/editor/js/angular-route.min.js:7:268) <div ng-view="" ng-show="main.results==null" class="ng-scope">我在我的index.html中包含了正确的文件:
<script src="/static/editor/js/angular.min.js"></script>
<script src="/static/editor/js/ng-file-upload-shim.js"></script>
<script src="/static/editor/js/ng-file-upload.js"></script>我将它声明为我的模块:
(function() {
angular
.module('myApp', [
'ngRoute',
'ngAnimate',
'ngCookies',
'ngFileUpload'
]);
})();但是当我试图将它注入到我的控制器中时,它抛出了上面的错误:
(function() {
angular
.module('myApp')
.controller('myController', myController);
myController.$inject = ['$routeParams',
'$compile',
'$scope',
'$interval',
'Upload'];
function myController($routeParams,
$compile,
$scope,
$interval,
Upload) {
....我使用的是Angular 1.4.6和ng-file-upload 9.0.14。我手动下载了这些文件,并将指定的.js文件包含在我的项目目录中。我是否遗漏了一些通过bower或npm包含的额外依赖项?
任何帮助都将不胜感激!
更新:使用AngularJS 1.4.6 (https://angular-file-upload.appspot.com/#/1.4.6)查看ng-file-upload指令的实时演示页面也会导致许多错误,因此这可能只是与1.4.6和最新版本的ng-file-upload不兼容。
发布于 2015-10-20 02:21:48
您正在尝试注入名为" upload“的未知服务,如果您指的是ng-file-upload的上传服务,则需要注入"ngFileUpload”而不是"Upload“。
myController.$inject = ['$routeParams',
'$compile',
'$scope',
'$interval',
'ngFileUpload'];
function myController($routeParams,
$compile,
$scope,
$interval,
ngFileUpload) {
....https://stackoverflow.com/questions/33220737
复制相似问题