我有文件上传,我可以上传文件,然后将控制器值放入输入隐藏值,因为我将发布表格。
HTML CODE
<input type="file" class="form-control" id="i_file5" file-model="process.step.file5" ng-file-select="onFileSelect($files5)" />
<input type="hidden" ng-model="{{files.name}}"/>
控制器代码
$scope.uploadResult = [];
$scope.onFileSelect = function($files) {
//$files: an array of files selected, each file has name, size, and type.
for (var i = 0; i < $files.length; i++) {
var $file = $files[i];
$upload.upload({
url: 'lib/fileupload/',
file: $file,
progress: function(e){}
}).then(function(response) {
// file is uploaded successfully
$timeout(function() {
$scope.uploadResult.push(response.data);
console.log($scope.uploadResult);
});
});
}
}
答案 0 :(得分:2)
我假设您已经在HTML中指定了控制器。如果没有,请按照以下示例所示实施。对于ng-model,您不应该使用{{ }}
,因为您绑定了不评估它的值。
<div ng-controller="files">
----
<input type="text" data-ng-model="files.name" style="display:none"/>
</div>