[英]File Upload reset in AngularJS
I am trying to create a image upload functionality in Angular 1. I have to allow user to upload image, remove the uploaded image, change the image.I am able to do all this but when the user removes the uploaded image and re-uploads the same image then change event is not firing and user is not able to upload the same image again. 我正在尝试在Angular 1中创建图像上载功能。我必须允许用户上载图像,删除上载的图像,更改图像。我能够执行所有操作,但是当用户删除上载的图像并重新上传时相同图片然后更改事件不会触发,并且用户无法再次上传相同图片。 Error on console is
Uncaught SyntaxError: Unexpected end of input
. 控制台上的错误是
Uncaught SyntaxError: Unexpected end of input
。 I am using Google Chrome. 我正在使用Google Chrome。 However, if we try to upload some other image then it works fine.
但是,如果我们尝试上传其他图像,则效果很好。
I have created a plunker to demo my code so far. 到目前为止,我已经创建了一个插件来演示我的代码。 Here is the link: https://plnkr.co/edit/bjdU2kuAqRA9yHE1CmX4?p=preview
这是链接: https : //plnkr.co/edit/bjdU2kuAqRA9yHE1CmX4?p=preview
Can someone help me to figure out what's the issue? 有人可以帮助我找出问题所在吗?
Edit: The default "Choose File" button and file name will be hidden using CSS in actual project. 编辑:默认的“选择文件”按钮和文件名将在实际项目中使用CSS隐藏。 Hence, I have binded file name and delete icon in HTML separately.
因此,我分别在HTML中绑定了文件名和删除图标。
When you remove the image, clear it from <input type="file">
such as: 删除图像时,请从
<input type="file">
清除图像,例如:
$scope.removeImage = function(){
document.getElementById("control").value = ""; <-- Add this line
$timeout(function(){
$scope.data.image = undefined;
}, 100);
};
Associate Id to <input type="file">
: 将ID关联到
<input type="file">
:
<input type="file" class="upload" file-model-no-preview="data.image" id="control"/>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.