Oops! Looks like the Digest is already being processed

I encountered the following issue:

Error: [$rootScope:inprog] $digest already in progress http://errors.angularjs.org/1.2.16/$rootScope/inprog?p0=%24digest

I'm uncertain about the root cause of this problem or what the terms "apply" and "digest" imply. Upon reading the documentation, I gathered that apply/digest is invoked on scope objects.

element.on('mouseup', function() {
 scope.$apply(function() {
 $scope.doStuff();
 });
});

This then transforms into:

$apply = function(fn) {
try {
  fn();
} finally() {
  $digest();
}
}

Answer №1

In the event that you invoke $scope.apply while the digest function is already running, this situation may arise. It is probable that your scope.apply is unnecessary and can be omitted.

According to Angular Docs: $digest() Processes all of the watchers of the current scope and its children. Typically, you do not call $digest() directly in controllers or directives.

Angular keeps track of the processing phase, with key phases being $apply and $digest. Attempting to reenter a $digest or $apply while one is currently in progress usually signifies a programming error that needs attention. Angular will generate an error notification when this occurs. Find more information here

Your code resembles an older technique that was required in earlier versions of angular(0.4 or 0.8) but is likely not necessary in the version of angular you are utilizing.

The Angular Team has provided a method to analyze these types of errors:

When encountering this error, pinpointing the cause can be challenging. The recommended approach is to examine the stack trace associated with the error. Look for instances where $apply or $digest have been called and determine the context in which this occurred.

There will typically be two calls:

The initial call is the proper $apply/$digest triggered by an event near the top of the call stack.

The subsequent call is the problematic $apply/$digest that requires investigation.

Once this call has been identified, navigate up the stack to identify the issue.

If the second call originates from your application code, investigate why it was invoked within a $apply/$digest. It could be an oversight or it might align with the sync/async scenario discussed previously.

If the second call is within an Angular directive, it likely matches the second programmatic event trigger scenario outlined earlier. In this case, explore further up the chain to determine the initial event trigger.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Displaying a message when jQuery autocomplete returns no results, and the submission cannot be completed

My expertise in jQuery is lacking, but I am trying to implement two functions simultaneously with the jQuery autocomplete feature. Firstly, I want to display a "no results found" message when there are no matches for the search input, and in this scenario, ...

AngularJS encountering unresponsive resources

When setting up my Angular App, I include various resources like this: angular.module('myApp', ['infinite-scroll', 'chieffancypants.loadingBar', 'ngResource']) Next, in the html file: <script type="text/javascr ...

Is it possible to collaborate using Ionic 2 and AngularJs 1?

Aspiring to create applications using Ionic 2, I am currently utilizing AngularJS1 with Ionic1. Although I find AngularJs 1 to be more familiar, AngularJS 2 poses a challenge. Is there a method to integrate Ionic 2 with AngularJS 1 seamlessly? ...

Combining various Google calendar feeds into a single JSON object using JavaScript

I'm currently in the process of integrating JSON feeds from multiple Google calendars to organize upcoming events and showcase the next X number of events in an "Upcoming Events" list. While I initially achieved this using Yahoo! Pipes, I aim to elim ...

Understanding the extent of testing coverage in a project using karma and webpack

For my project, I am incorporating ES6 syntax and testing my code with Karma. While I have successfully set up testing, I encountered an issue with the coverage report. Instead of including the source code, the coverage report is highlighting spec file ...

Typescript selection missing in Intellij IDEA when creating new Step definition File for Protractor and Cucumber

Currently working on: Protractor Cucumber and Typescript project Preferred IDE: Intellij IDEA Ultimate edition Any suggestions on what I might be overlooking? List of added plugins: 1. Javascript Support 2. Node.js ...

What is the method for dividing a string into separate parts without the use of del

I have the number "513" in a string format, and I need to convert it into an array consisting of ["5", "1", "3"]. My updated solution using code is: function convertToArray(num){ let numArray = num.split(''); console.log(numArray); } co ...

Issue encountered with Ionic and Angular 2: Denied application of style from 'http://localhost:8100/build/main.css' due to unsupported MIME type ('text/html')

Initially, everything was going smoothly with my Ionic build, but things took a turn when I tried to test it on my iPhone. After stopping the server and running ionic serve --address localhost, I noticed that my stylesheet wasn't loading. Even after r ...

Adjusting images correctly and enlarging on hover

Currently, I am facing two challenges that I need assistance with. Firstly, I am struggling to properly fit my images in a way that allows the person in the picture to be visible while still filling the entire screen. Secondly, I am looking for guidance on ...

Avoid displaying pop-up repeatedly (using current library)

I am currently customizing a Shopify theme that includes its own popup settings. I have created a new popup for my website that prompts visitors to choose their preferred language upon arrival. Everything seems to be working fine up to this point, but the ...

I need assistance with incorporating a datepicker feature using jQuery UI

Can someone please assist me? I am trying to incorporate a datepicker (Jquery UI) and add an additional function in the script for counting, but my understanding of jquery is limited. (My English skills are also lacking, apologies in advance) I would dee ...

I am facing a problem with the API routes in my Next.js project as the req.query object is coming up as undefined

Issue: I'm facing a problem with accessing query parameters in my API route. Despite sending the correct URL with the query parameter, req.query is returning undefined data instead of the expected values. Here's the Request Handling Code: impor ...

Encountering an issue while attempting to import JSON data into an Angular component

Looking to create a straightforward photo gallery using angularJs. The goal is to pull images from a json file and showcase them on the view file. The idea is that once a tab is clicked, the corresponding images should be displayed. Controller $scope.loa ...

Exploring Raycasting with Three.js and WhitestormJS

Having trouble with Raycasting in Three.js and WhitestormJS. Perhaps I haven't grasped the concept properly. The goal is to align the raycaster's direction with the camera, so that when it intersects an element, that element is added to the inte ...

What steps should I take in order to protect an MP3 link?

I am currently developing a music website that offers free streaming of music, but I want to prevent users from downloading the mp3 files directly from my server. My backend is built on Laravel v5.4 framework and frontend is using Angular v5.5. The music ...

Difficulty in detecting state changes without refreshing the component when using Redux and React

I'm encountering difficulties detecting state changes from my Redux reducer in a React application. When I modify the state within one component, the other component in the app does not get the update unless the component is reloaded or refreshed. Let ...

AngularJS directive that formats currency based on the selected language for translation

In my project, I am working on formatting numbers as currency, including decimals and using commas or points to separate thousands. app.directive('format', ['$filter', function ($filter) { return { require: '?ngModel&a ...

Dropping and dragging in the Dojo for the nested lists

Within my HTML code, I am using the Dojo drag and drop feature to sort attributes and move them to another section. However, I am having trouble figuring out how to sort the sections themselves. Here is the structure that I have created: <ul accept=" ...

What could be causing an event not to load in Ionic 2?

I've written a function in my home.ts file; launch(url) { this.platform.ready().then(() => { alert('hello'); let ref = new InAppBrowser(url); ref.on('loadstart').lift(() => { alert(& ...

Web application designed with an app grid similar to the layout of an iPhone or Android interface

I would like to create a homepage similar to the layout of an "iPhone / Android" home screen, with multiple apps displayed on a webpage. Specifically, I am looking to replicate ERPNext's front page design. Does anyone have any examples or templates t ...