Skip to content
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 opened this issue Mar 21, 2014 · 2 comments

Comments

@haimlit
Copy link

haimlit commented Mar 21, 2014

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.

@caitp
Copy link
Contributor

caitp commented Mar 21, 2014

Hi, this is a duplicate of #6364 (and various others), can we move the discussion over there?

@haimlit
Copy link
Author

haimlit commented Mar 21, 2014

Oh, sorry, sure.

@haimlit haimlit closed this as completed Mar 21, 2014
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants