首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用ng-file-upload接收"Unknown provider: UploadProvider“错误

使用ng-file-upload接收"Unknown provider: UploadProvider“错误
EN

Stack Overflow用户
提问于 2015-10-20 01:46:39
回答 1查看 2.1K关注 0票数 4

我尝试使用ng-file-upload指令(https://github.com/danialfarid/ng-file-upload)将文件上传功能添加到我的项目中,但一直收到以下错误:

代码语言:javascript
复制
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中包含了正确的文件:

代码语言:javascript
复制
<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>

我将它声明为我的模块:

代码语言:javascript
复制
(function() {
    angular
        .module('myApp', [
            'ngRoute',
            'ngAnimate',
            'ngCookies',
            'ngFileUpload'
    ]);
})();

但是当我试图将它注入到我的控制器中时,它抛出了上面的错误:

代码语言:javascript
复制
(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不兼容。

EN

回答 1

Stack Overflow用户

发布于 2015-10-20 02:21:48

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

代码语言:javascript
复制
  myController.$inject = ['$routeParams',
        '$compile',
        '$scope',
        '$interval',
        'ngFileUpload'];

function myController($routeParams,
    $compile,
    $scope,
    $interval,
    ngFileUpload) {
....
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33220737

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档