Skip to content
This repository was archived by the owner on Oct 2, 2019. It is now read-only.

Prevent '$apply already in progress' error at angular v1.3.0-beta-12+ #137

Merged
merged 1 commit into from
Aug 2, 2014

Conversation

dimirc
Copy link
Contributor

@dimirc dimirc commented Aug 2, 2014

Problem was caused by this commit in angular code.

I already also send them a comment with a proposal on how to prevent this.

If they don't fix/change at angular's end, then I'll merge this in couple of days.

Working plunker

Closes #124

dimirc added a commit that referenced this pull request Aug 2, 2014
Prevent '$apply already in progress' error at angular v1.3.0-beta-12+
@dimirc dimirc merged commit 5a95ef0 into master Aug 2, 2014
@dimirc dimirc deleted the fix-apply-angular1.3-beta branch August 2, 2014 15:58
@tikiatua
Copy link

tikiatua commented Aug 2, 2014

@dimirc thank you for looking into the issue. That might have been the case. This would also explain, why I could not reproduce the problem on plunkr where I was using a stable release of angular.

@dimirc dimirc restored the fix-apply-angular1.3-beta branch August 3, 2014 03:24
@petebacondarwin
Copy link
Member

@dimirc - Are you sure this fixes the problem? The way you have done it, the call to focus() will still be inside a $apply block. You need to tell $timeout not to wrap the function in an apply:

$timeout(function(){
  ctrl.focusser[0].focus();          
}, 0, false);

Perhaps a unit test will help nail this down?

@dimirc
Copy link
Contributor Author

dimirc commented Aug 3, 2014

@petebacondarwin before the $timeout we have this line ctrl.open = false; that will hide the search input that was the element in conflict.

This fix actually works since I'm defering the focus() event to next cycle where there isn't a search input shown anymore so no .blur() event that will conflict neither.

Anyway I think that your suggestion of setting the timeout with invokeApply = false is valid since we'll prevent an unnecessary digest cycle.

Landed as 6dfc5d0

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.

Broken with Angular 1.3.0-beta-16
3 participants