我正在尝试使用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不兼容.
解决方法
您正在尝试注入名为“上传”的未知服务,如果您的意思是ng-file-upload的上传服务,则需要注入“ngFileUpload”而不是“Upload”.
myController.$inject = ['$routeParams','ngFileUpload']; function myController($routeParams,ngFileUpload) { ....