0

I have this function:

function scopeMutateSuccess(modalInstance, state) { $rootScope.$apply(function() { modalEventConfig.statusType = 'success'; modalEventConfig.nodeStatus = 'Completed Successfully'; }); } 

In the call stack...there a is a digest() that is called before this function. However, it is still running while this function gets called and I get a digest() already in progress. I need my own digest() in this function or otherwise the view does not get updated with the scope member values. The first digest() is being called somewhere else and not by me so I can't controller it firing.

Is there a event listener for when a digest() ends or a way to keep them from clashing?

15
  • 1
    Why are you doing $rootScope.$apply() ? Anyhow take a look at this github.com/yearofmoo/AngularJS-Scope.SafeApply/blob/master/src/… Commented Aug 24, 2014 at 21:23
  • because this is in a service which doesn't use local scopes. Commented Aug 24, 2014 at 21:24
  • Can you elaborate? Definitely mostly this is design problem because of which you end up invoking the digest cycle manually.. Commented Aug 24, 2014 at 21:24
  • 1
    You should always trigger the digest from the root of the stack, namely when an event occurs, like a user click or a resolved xhr request. Understanding the stacktrace is fundamental to understand angular digests. Commented Aug 24, 2014 at 21:28
  • 1
    @dman storing data and triggering a digest are not the same thing. If you want to trigger a digest that's because there is an event which happens 'outside' angular. Unfortunately, If that event didn't trigger a digest you'll find yourself triggering it down the stack which is bad.. Commented Aug 24, 2014 at 21:34

1 Answer 1

2

You can always check for digest in progress using $scope.$$phase (returns true if it's in progress).

However, the simplest fix here seems to be just to wrap the inside function into a $timeout callback (which takes care of the in-progress issue for you), like this:

function scopeMutateSuccess(modalInstance, state) { $timeout(function() { modalEventConfig.statusType = 'success'; modalEventConfig.nodeStatus = 'Completed Successfully'; }, 0); } 

Make sure you inject the $timeout dependency, of course.

Sign up to request clarification or add additional context in comments.

1 Comment

Normally this would work, but after much trouble shooting my issue goes further than this...so, I will have to make a new post since the root problem is something else.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.