(Implicitly) triggering browser events from Angular event handlers #1342
Description
Imagine an Angular event handler, eg. an ng-click handler, that wants to focus a particular text field (probably as part of a directive, not in the controller itself):
function handleClick() {
someNode.focus();
}
Now the focus triggers an onFocus event by itself, which if listened to will likely trigger a scope.$apply. Because we're already in a digest cycle, this will trigger an error ('digest already in progress').
Currently the only way out of that is going asynchronous via $timeout. That makes testing much harder, causes another unnecessary cycle immediately after the current, and also turns a detectable loop condition ('more than XXX digest iterations') into a possible infinite 100% CPU loop.
It would be nice if there was an API to detect the condition, or to say "$apply within the current cycle, and trigger one if not already in progress".