Skip to content
This repository has been archived by the owner on Sep 8, 2020. It is now read-only.

blurHandler #170

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

flaviodamaiajr
Copy link

Added condition to check $$phase on $rootScope.

Added condition to check $$phase on $rootScope.
@lukepfeiffer10
Copy link
Contributor

Are you running into an issue where a $digest is already in progress?

Also, this is a discouraged use of $$phase and I would rather not incorporate it into the library.

source: https://github.com/angular/angular.js/wiki/Anti-Patterns

@shizik
Copy link

shizik commented Aug 19, 2016

I have the same issue ($digest already in progress). Any ideas how to handle this without checking the $$phase property?

@blittle
Copy link

blittle commented Sep 19, 2016

Generally it is considered safe to do the following:

$timeout(() => {
  $scope.$apply(() => {
     if (!controller.$pristine) {
       controller.$setViewValue('');
     }
  });
}, 0, false);

By using $timeout you are guaranteed to already be in a digest and by passing false as a third parameter $rootScope won't trigger its own digest. The only potential issue is that this will be on another run of the event loop, but given the above code I think it should be fine.

@zamb3zi
Copy link

zamb3zi commented Oct 19, 2017

This bug is still causing issues. The modern solution is to simply replace all calls to $apply with $applyAsync (introduced in Angular 1.2).
I'm deploying my own corrected version of the directive for now.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants