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.

focusing (from angular context) on an element which has ngFocus will cause '$apply already in progress' exception #6791

Closed
@haimlit

Description

@haimlit

Hi,

If we'll focus on an element from angular context, and that element has ngFocus, we will get '$apply already in progress' exception. You can see it happen in the following plunkr:
http://plnkr.co/edit/R6ZDD8kVGu3SpzHY4CVT?p=preview **

Focusing and blurring with the cursor works fine, like it should. However when clicking on the 'Click to focus on input' button, we will get the exception (see console).

This issue can be solved in the directives of ngFocus, ngBlur and the rest of the events by checking if digest is already in progress (scope.$root.$$phase). However, I don't think that checking digest state on a plain directive is the 'angular way' of doing things, so maybe I'm missing something here. If you do think it's the way to do it, I don't mind writing it.

** I know that fiddling with DOM on the controller is bad practice, it's just to keep the example simple, it can be easily reproduced on a better-practice directive with an ngClick handler that does the same thing.

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