我尝试使用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。
答案 0 :(得分:1)
您正在尝试注入名为“上传”的未知服务,如果您指的是ng-file-upload的上传服务,则需要注入“ngFileUpload”而不是“上传”。
myController.$inject = ['$routeParams',
'$compile',
'$scope',
'$interval',
'ngFileUpload'];
function myController($routeParams,
$compile,
$scope,
$interval,
ngFileUpload) {
....