You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
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".
The text was updated successfully, but these errors were encountered:
I think when doing elm.focus() you need to use setTimeout / $timeout anyway, otherwise it might not get focused.
You can use $timeout(fn, 0, false) that won't cause $apply.
You can check, whether $apply is in progress, just do: if (!scope.$root.$$phase) scope.$apply();
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".
The text was updated successfully, but these errors were encountered: