Reputation: 898
Hy I have a div that simulates an input file button. To achieve this I did
angular.element('#fileInput').trigger('click');
but this generated an Apply already in progress error, googling around I found that this could easily be avoided putting the code inside a timeout.
timeOut = $timeout(function(){
angular.element('#fileInput').trigger('click');
});
And as an effect that really solved the problem, but $timeout generates an infinite loop opening infinite file dialogs if my pop-up block is disabled. In the AngularJS docs you can clearly read that $timeout is a wrapper of setTimeout wich should only generate one call to the callback function, so why is it generating an infinite loop? However, trying to solve the situtation I decided to kill the timer after the first call, but I couldn't manage,
timeOut = $timeout(function(){
angular.element('#fileInput').trigger('click');
});
timeOut.then( function( ){$timeout.cancel(timeOut);
}
);
I'm getting quite stuck in this situation... I'm I just missing something obvious things? Someone has any idea's? thank's
Upvotes: 1
Views: 3532
Reputation: 16056
why instead of using a $timeout you try to us an $interval and set it to run one time?
var interval = $interval(function() {
angular.element('#fileInput').trigger('click');
}, 100,1);
Upvotes: 2