[英]How to reset the file upload control in Angular JS
In my app I have a file upload control , 在我的应用程序中,我有一个文件上传控件,
<label>Upload File</label>
<div class="ui-select">
<input type="file" name="files" ng-files="getTheFiles($files)" />
</div>
And the controller code that helps uploading files is ... 有助于上传文件的控制器代码是......
$scope.file = null;
//UPLOAD FILE CODE
var formdata;
$scope.getTheFiles = function ($files) {
console.log($files[0].type);
formdata = new FormData();
angular.forEach($files, function (value, key) {
formdata.append(key, value);
});
};
// NOW UPLOAD THE FILES.
$scope.uploadFiles = function () {
var request = {
method: 'POST',
url: BasePath + 'uploadNative/UploadFiles/',
data: formdata,
headers: {
'Content-Type': undefined
}
};
// SEND THE FILES.
console.log(formdata);
if (formdata != null || formdata != undefined) {
$http(request)
.success(function (response) {
if (response != "Failed!" && response !="FileAlreadyUploaded") {
console.log("Succeeds");
}
else if(response == "FileAlreadyUploaded")
{
angular.element("#fileUploadModal").modal();
}
else {
console.log("Failed");
}
})
.error(function () {
});
}
I want the file upload control to be cleared up upon success or failure ie 我希望在成功或失败时清除文件上传控件,即
after 后
angular.element("#fileUploadModal").modal();
shows up the modal , I want the control to be cleared up . 显示模态,我想要清除控件。 How would I do that ? 我该怎么办? Please explain. 请解释。
Set an id
to file upload control
设置id
到file upload control
Html: HTML:
<input id= "control" type="file" name="files" ng-files="getTheFiles($files)" />
Controller: 控制器:
angular.element("#control").value = "";
Add ng-click to your input: 添加ng-click到您的输入:
<input ng-click="reset()" id= "control" type="file" name="files" ng-files="getTheFiles($files)" />
and in your controller create a reset method: 并在您的控制器中创建一个重置方法:
$scope.reset= function () {
angular.element("input[type='file']").val(null);
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.