我已在视图中包含了所有必需的文件:
<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>
我的模块和控制器:
var controllers = angular.module('controllers', ['ngGrid', 'ngDialog', 'angularFileUpload']);
controllers.controller('CustomProductsCtrl',
['$scope', '$window', 'ngDialog', 'CommonService',
'CustomProductsServices', '$upload',
function ($scope, $window, ngDialog, CommonService,
CustomProductsServices, $upload){
});
但我仍然收到此错误。
错误:[$ injector:unpr]未知提供商:$ uploadProvider
请帮帮我。
答案 0 :(得分:6)
遇到同样的问题,原来注入$ upload的文档已经过时了,应该是FileUploader:
controllers.controller('CustomProductsCtrl',
[..., '$upload', function (..., 'FileUploader') {
花费的时间比我想承认的更多。仅供参考,我通过查看angular-file-upload.js来确定:
.factory('FileUploader', ['fileUploaderOptions', '$rootScope', '$http', '$window', '$compile',
答案 1 :(得分: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
因为我们需要遵循declaring a controller的形式。 controller API很简洁,但非常简洁:
$controller(constructor, locals);
扩展到您的案例:
module_name.controller( 'your_Ctrl',
[locals, function(){
}
]
);
我添加了额外的间距来调出缺少的]
并显示我们如何关闭声明中的元素。
答案 2 :(得分: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
...
})