4

我正在尝试使用 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 不兼容。

4

1 回答 1

1

您正在尝试注入名为“Upload”的未知服务,如果您的意思是 ng-file-upload 的上传服务,您需要注入“ngFileUpload”而不是“Upload”。

  myController.$inject = ['$routeParams',
        '$compile',
        '$scope',
        '$interval',
        'ngFileUpload'];

function myController($routeParams,
    $compile,
    $scope,
    $interval,
    ngFileUpload) {
....
于 2015-10-19T18:21:47.683 回答