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

fix(input): $evalAsync than $apply on input blur#8400

Closed
PatrickJS wants to merge 1 commit into
angular:masterfrom
PatrickJS:patch-2
Closed

fix(input): $evalAsync than $apply on input blur#8400
PatrickJS wants to merge 1 commit into
angular:masterfrom
PatrickJS:patch-2

Conversation

@PatrickJS
Copy link
Copy Markdown
Contributor

without $evalAsync I would have to wrap a few directives in a setTimeout to prevent digest loop conflicts

angular.module('directives', [])
.directive('focusOn', function($parse) {
  return function(scope, element, attrs) {

    // avoid $digest in progress
    setTimeout(function() {
      var getter = $parse(attrs.focusOn);
      if (getter(scope)) {
        element[0].focus();
      }
    }, 0);

  };

})

without $evalAsync I would have to wrap a few directives in a setTimeout to prevent digest loop conflicts
```javascript
angular.module('directives', [])
.directive('focusOn', function($parse) {
  return function(scope, element, attrs) {

    // avoid $digest in progress
    setTimeout(function() {
      var getter = $parse(attrs.focusOn);
      if (getter(scope)) {
        element[0].focus();
      }
    }, 0);

  };

})
```
@Narretz Narretz added this to the 1.3.0 milestone Jul 30, 2014
@Narretz
Copy link
Copy Markdown
Contributor

Narretz commented Jul 30, 2014

This is similar to #6910
$evalAsync is probably the most unstable way to fix this because you cannot guarantee that digest and event loop are in sync (though it worked for me). "safe apply" is the better idea, although @petebacondarwin says it won't work.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants