使用注入时,ng文件上传不适用于MEAN.JS应用程序



抛出错误:

angular.js:13920 Error: [$injector:unpr] Unknown provider: ngFileUploadProvider <- ngFileUpload <- MyCtrl
http://errors.angularjs.org/1.5.8/$injector/unpr?p0=ngFileUploadProvider%20%3C-%20ngFileUpload%20%3C-%20MyCtrl
    at http://192.168.99.100:3000/lib/angular/angular.js:68:12
    at http://192.168.99.100:3000/lib/angular/angular.js:4511:19
    at Object.getService [as get] 

当Controller定义如下时:

(function ($, angular) {
'use strict';
angular.module('myapp').controller('MyCtrl', MyCtrl);
  function MyCtrl(
    $scope,
    $q,
    $stateParams,
    Upload,
    $timeout
  ){
    var vm = this;
    function setup(){
      vm.stateParams = $stateParams;
      //set scope variables here
      viewApi();
    }
    function viewApi(){
      vm.uploadImage = function(file, errFiles) {
        vm.uploadedThumbnail = file;
        vm.errFile = errFiles && errFiles[0];
        if (file) {
          file.upload = Upload.upload({
            url: 'https://angular-file-upload-cors-srv.appspot.com/upload',
            data: { file: file }
          });
          file.upload.then(uploadSuccess, uploadError, uploadEvent);
        }
      };
    }
    ... 
    setup();
  }
  MyCtrl.$inject = [
    '$scope',
    '$q',
    '$stateParams',
    'ngFileUpload', // Note that 'Upload' doesn't work either
    '$timeout'
  ];
}(window.jQuery || window.$, window.angular));

我尝试了ngFileUpload,只是上传相同的结果。所有的依赖都被声明和加载。

需要将ngFileUpload添加到模块定义中,如下所示:

angular.module('myapp', ['ngFileUpload', 'ui.router', 'other.dependencies', ...]).controller('MyCtrl', MyCtrl);
...

实际上,我发现解决方案相对简单:

角。模块("myapp",[' ngFileUpload '])。控制器(MyCtrl, MyCtrl);

它解决了上面的问题,但通过删除应用状态提供者产生了一个新问题:angular.js:68未捕获错误:[$injector:modulerr]实例化模块myapp失败,原因如下:错误:[$injector:unpr]未知提供商:$stateProviderhttp://errors.angularjs.org/1.5.8/$喷射器/unpr ? p0 = % 24 stateprovider

所以我们通过创建一个新问题来解决一个问题。

现在的新问题是:如何添加'ngFileUpload'依赖而不覆盖其他应用程序的依赖。

相关内容

  • 没有找到相关文章

最新更新