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

Error: $digest already in progress exception using element.focus in directive #1250

Closed
johntowell opened this issue Aug 9, 2012 · 5 comments

Comments

@johntowell
Copy link

Here is a jsfiddle showing the bug

http://jsfiddle.net/jtowell/xK28W/

I was able to get it to work by wrapping in settimeout. Here is working version

http://jsfiddle.net/jtowell/j8hnr/

@vojtajina
Copy link
Contributor

Not sure that this is a bug in Angular.

To get this working, you have to use setTimeout / $timeout service, otherwise you are trying to focus hidden element (the select becomes visible after your .focus() call).

Plus .focus() triggers DOM event (synchronously) - so as long as you have some other directive listening on fired even (in this case ui-event listens on blur), it tries to do $apply() within $apply.

@mhevery
Copy link
Contributor

mhevery commented Sep 17, 2012

I actually think there should be a way to support this without resolving to
timeout.

On Thu, Sep 13, 2012 at 2:59 AM, Vojta Jina [email protected]:

Not sure that this is a bug in Angular.

To get this working, you have to use setTimeout / $timeout service,
otherwise you are trying to focus hidden element (the select becomes
visible after your .focus() call).

Plus .focus() triggers DOM event (synchronously) - so as long as you have
some other directive listening on fired even (in this case ui-event listens
on blur), it tries to do $apply() within $apply.


Reply to this email directly or view it on GitHubhttps://github.com//issues/1250#issuecomment-8523479.

@mhevery
Copy link
Contributor

mhevery commented Sep 17, 2012

perhaps something like asyncEval but asyncPostDigest

On Sun, Sep 16, 2012 at 9:13 PM, Misko Hevery [email protected] wrote:

I actually think there should be a way to support this without resolving
to timeout.

On Thu, Sep 13, 2012 at 2:59 AM, Vojta Jina [email protected]:

Not sure that this is a bug in Angular.

To get this working, you have to use setTimeout / $timeout service,
otherwise you are trying to focus hidden element (the select becomes
visible after your .focus() call).

Plus .focus() triggers DOM event (synchronously) - so as long as you have
some other directive listening on fired even (in this case ui-event listens
on blur), it tries to do $apply() within $apply.


Reply to this email directly or view it on GitHubhttps://github.com//issues/1250#issuecomment-8523479.

@cj
Copy link

cj commented Oct 17, 2012

I've been having the same issue, where parent scopes weren't getting updated straight away using $watch until the next time $apply/$digest was called. So I had to resort to using the setTimeout method @johntowell used. I'll make a plunker here later today.

@btford
Copy link
Contributor

btford commented Dec 20, 2013

$timeout is a pragmatic approach for Angular 1.x. In the future, this will (hopefully) be solved with Object.observe.

@btford btford closed this as completed Dec 20, 2013
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

5 participants