a Angular JS dark pattern to avoid.
If you're writing AngularJS you may have seen this error before
Error: $digest already in progress
And to avoid it people have mentioned that you can do the following to check if a $digest is already in progress.
if (!scope.$$phase) {
// Your Logic
}
But this is not a future-proof way to do it, nor does it guarantee that your logic executes on the next digest loop which is probably what you wanted to happen ( i.e. you changed the scope variable to a different string ). If you want to guarantee that your logic will execute on the next digest loop, do something like this.
$timeout(function() {
// Your Logic
});
Written by Jimmy Lee
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Angularjs
Authors
Related Tags
#angularjs
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#