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.

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

Closed

Description

@johntowell

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/

Activity

  1. vojtajina commented on Sep 13, 2012

    @vojtajina
    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.

  2. mhevery commented on Sep 17, 2012

    @mhevery
    Contributor

    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.

  3. mhevery commented on Sep 17, 2012

    @mhevery
    Contributor

    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.

  4. cj commented on Oct 17, 2012

    @cj

    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.

  5. btford commented on Dec 20, 2013

    @btford
    Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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