Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

(Implicitly) triggering browser events from Angular event handlers #1342

Closed
@mprobst

Description

@mprobst

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".

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions