I take a code that works very well on IE and testing on Chrome, I see that the browser does not wait until the user has chosen his file before continuing to execute the code.
HTML :
<input type="file" accept=".jpg" id="flNewDoc" name="flNewDoc"
style="display:none" />
<input ng-model="vm.currentPiece.OriginalName" type="text" id="txtNewFile"
readonly />
<button type="button" ng-click="vm.openFileDialog()">
<i class="fa fa-folder-open-o"></i>
</button>
AngularJS controller :
vm.openFileDialog = function () {
var element = angular.element('#flNewDoc');
element.trigger('click');
console.log("click triggered");
vm.newFile = element[0].files[0];
vm.newFileName = element[0].value;
vm.uploadFile();
console.log("file upload ended");
};
vm.uploadFile = function () {
if (vm.newFile) {
vm.currentPiece = {
isNew: true,
isToDelete: false,
isLoading: true,
};
dataSrv.uploadReunionDocument(vm.newFile).then(function (resp) {
Object.assign(vm.currentPiece, resp.data)
vm.currentPiece.isLoading = false;
vm.newFile = undefined;
vm.newFileName = '';
}, function (error) {
vm.currentPiece.isLoading = false;
console.log(error);
});
}
};
With IE my code block is paused on the line element.trigger('click')
The user can therefore select his file and the download starts directly (client request). While in chrome, we see the selection window open, but the code continues without pausing
How can I adapt my code so that it works as expected on both browsers?