I've been struggling with this issue for a long time and have not been able to find a solution. The problem arises when attempting to trigger a click event on a file input type from within a promise. When I directly trigger the event inside the promise, an error is logged in the console stating "digest in progress." If I insert a timeout within the promise, the error disappears but the event still does not get triggered. The only workaround I've found is adding a setTimeout function outside the promise for around one second, which I do not want to rely on.
The controller code snippet appears as follows:
scope.handleDblClick = function () {
asyncFunction()
.then(function (response){
switch(response){
case 'option1':
//do something
break;
case 'option2':
document.getElementById('fileInputId').click();
break;
}
});
}
This function is activated upon double clicking on a text input field.
<input type="text" ng-dblclick="handleDblClick()"/>
This is the file input that needs to be clicked within the promise.
<input type="file" id="fileInputId"/>
The event must be triggered in this manner because the outcome of the async function determines whether the file input will be clicked or another action will be taken. The handleDblClick function executes different actions based on the promise response, including opening a file explorer to select a file.