When I pick an image, at times it does not display, but when I click a second time, the image is displayed.
jQuery
$('#morefiles').change(function (event) {
if (!(/\.(gif|jpg|jpeg|tiff|png)$/i).test($(this).val())) {
$ionicPopup.alert({
title: 'Message',
template: 'You must select an image file only !'
});
$('#morefiles').val('');
} else {
var obj = {};
obj.key = event.target.files[0];
obj.value = URL.createObjectURL(event.target.files[0]);
$scope.items.push(obj);
console.log(JSON.stringify(obj));
$('#morefiles').val(obj);
}
});
HTML
<input type="file" multiple="" id="morefiles" accept="image/*" >
How to solve this problem? When the user selects an image I need to display the image at that time. Thanks in advance.