4

This is not a duplicate of This Question

I have included all the required files in view:

<script src="~/Scripts/angular-file-upload-master/examples/console-sham.min.js"></script>
<script src="~/Content/js/angular.js"></script>
<script src="~/Scripts/angular-file-upload-master/angular-file-upload.js"></script>

My module and controller:

var controllers = angular.module('controllers', ['ngGrid', 'ngDialog', 'angularFileUpload']);

controllers.controller('CustomProductsCtrl', 
 ['$scope', '$window', 'ngDialog', 'CommonService', 
   'CustomProductsServices', '$upload', 
 function ($scope, $window, ngDialog, CommonService, 
   CustomProductsServices, $upload){

});

But still I get this error.

Error: [$injector:unpr] Unknown provider: $uploadProvider

Please help me out.

4

3 回答 3

6

遇到同样的问题,原来注入$upload的文档已经过时了,应该是FileUploader:

controllers.controller('CustomProductsCtrl',
  [..., '$upload', function (..., 'FileUploader') {

花费的时间比我想承认的要多。仅供参考,我通过查看 angular-file-upload.js 确定了这一点:

.factory('FileUploader', ['fileUploaderOptions', '$rootScope', '$http', '$window', '$compile',
于 2015-01-20T19:58:36.373 回答
2

看来您没有controller正确关闭声明。

具体来说,你有:});什么时候你应该有}]);。注意缺少的].


在上下文中,您应该具有:

var controllers = angular.module('controllers', ['ngGrid', 'ngDialog', 'angularFileUpload']);

controllers.controller('CustomProductsCtrl', 
 ['$scope', '$window', 'ngDialog', 'CommonService', 
   'CustomProductsServices', '$upload', 
 function ($scope, $window, ngDialog, CommonService, 
   CustomProductsServices, $upload){

}]);  // Note: missing ']' added in here

因为我们需要遵循声明控制器的形式。控制器 API很简洁,但非常简洁:

$controller(constructor, locals);

扩展到您的情况:

module_name.controller( 'your_Ctrl', 
    [locals, function(){ 
        } 
    ] 
);

我添加了额外的间距来标注缺失的部分]并显示我们如何关闭声明中的元素。

于 2015-01-14T22:03:20.510 回答
0

似乎此错误可能与 ng-file-upload 版本有关:

https://github.com/danialfarid/ng-file-upload/issues/45

如果您尝试该页面和此页面上的建议但仍然收到错误,则以下内容对我有用:

angular.module('starter.controllers', ['ngFileUpload'])
.controller('HomeCtrl', function($scope, ... Upload) {
   ...
   file.upload = Upload.upload({...}); //Upload instead of $upload
   ...
})
于 2016-09-01T12:16:02.630 回答