我试图将工厂添加到我的" ng-file-upload"控制器(实际上是他们文档中的复制粘贴)......但不幸的是它不能为我工作
以下是一些代码示例
厂:
weekly_report_app.factory('sharedData', function () {
var data = {
value: "initial value"
};
return {
getValue: function() {
return data.value;
},
updateValue: function(value) {
data.value = value;
}
};
});
控制器:
weekly_report_app.controller('uploadCtrl', [ '$scope', 'Upload', 'sharedData', function($scope, Upload, sharedData) {
$scope.attachments_counter = 0;
$scope.$watch('files', function () {
$scope.upload($scope.files);
});
$scope.upload = function (files) {
if (files && files.length) {
for (var i = 0; i < files.length; i++) {
$scope.attachments_counter++;
sharedData.getValue(); // Error: [$injector:unpr] http://errors.angularjs.org/1.3.10/$injector/unpr?p0=sharedDataProvider%20%3C-%20sharedData%20%3C-%20uploadCtrl
var file = files[i];
Upload.upload({
url: 'uploads',
fields: {
'username': "test_name",
'team': "test_team",
'project_name': "test_project",
'task_name': "test_task"
},
file: file
}).progress(function (evt) {
var progressPercentage = parseInt(100.0 * evt.loaded / evt.total);
console.log('progress: ' + progressPercentage + '% ' + evt.config.file.name);
}).success(function (data, status, headers, config) {
console.log('file ' + config.file.name + 'uploaded successfuly. Response: ' + data);
});
}
}
};
}]);
我做错了什么?