Child component destruction triggers an ongoing digestion process

I am facing a strange issue within my AngularJS application. The error I'm encountering is the common $digest already in process error. Despite searching online and reviewing similar questions, none of the proposed solutions have resolved the issue. The error specifically occurs in a child component. This child component essentially acts as a wrapper around a standard text input with some added styling. The ng-model of the child component is bound to the item passed into it. Additionally, the child component emits events when the input is either focused or blurred. The hierarchy of components is structured as follows: There's a parent component functioning as a modal, and the child component comprises a text input. The parent component (modal) can be closed using the ESC key. The error arises when I open the modal, select the input (without entering any text), and then close it using the ESC key.

Below is the template for the child component:

<div class="input-group has-feedback"'
     ng-class="{'has-error' : vm.item.errors.length > 0 ,
                'has-success' : vm.item.isFulfilled}">
        <div class="input-group-addon">
            <i class="fa fa-asterisk"></i>
        </div>
            <input
            ng-model="vm.item.pendingBarcode"
            type="text"/>
</div>

Here is the JavaScript code for the child component:

.component('rfidInput', {
        templateUrl: 
'swipeables/templates/swipeables.rfidReader.tpl.html',
        controllerAs: 'vm',
        bindings: {
            item: '<',
            id: '<',
            onFocus: '&',
            onBlur: '&',
            focus: '<'
        },
        controller: function() {

            this.onInputFocus = function() {
                if(typeof this.onFocus === 'function') {
                    this.onFocus({index:this.id})
                }
            }

            this.onInputBlur = function() {
                if(typeof this.onBlur === 'function') {
                    this.onBlur({item:this.item});
                }
            }
        }
    })

I simplified the child component's template to just include the ng-model, even though there are also bindings for ng-blur and

ng-focus</code, which I removed to pinpoint the source of the problem.</p>

<p>This is how the parent template utilizes the child template:</p>

<pre><code><rfid-input on-blur="fulfill(item)" focus="currentFocusedScanIndex"
            on-focus="onScanFocus(index)" item="item" id="$index">
</rfid-input>

An interesting observation is that the error only occurs when I click into the input and then close the modal. If I open the modal but do not select the input before closing it, the error does not occur...

I am stuck and unsure of how to resolve this issue. I attempted using the $timeout solution to trigger onFocus and onBlur after a delay to prevent interference with the current $digest cycle.

Any assistance or suggestions on resolving this problem would be greatly appreciated. Additionally, any advice on improving the child component would be helpful as well.

Answer №1

According to the Documentation:

Finding the Root of This Issue

Encountering this error can be overwhelming when trying to pinpoint the cause of the problem. The most effective approach is to analyze the stack trace from the error. Look for instances where $apply or $digest have been invoked and determine the context in which it happened.

There are typically two occurrences:

The initial invocation is the correct $apply/$digest and is usually triggered by an event at the top of the call stack.

The subsequent invocation is the problematic $apply/$digest and requires further investigation.

Once you have identified this invocation, trace back through the stack to identify the root cause of the issue.

If the second invocation originated within your application code, evaluate why this code was executed within an $apply/$digest. It could be a simple oversight or align with the sync/async scenario mentioned earlier.

If the second call occurred within an AngularJS directive, it likely corresponds to the second programmatically induced event situation described earlier. In such cases, you might need to investigate higher up the hierarchy to determine what triggered the initial event.

For additional details, visit AngularJS Error Reference - inprog - Diagnosing This Error.

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

Creating a custom arrow design for a select input field using CSS

I'm currently developing a website (using Wordpress with a custom theme) and I want to incorporate an up/down arrow in the select input field using CSS. The HTML code I have for creating the up/down arrow in the select input field is as follows: < ...

The database is not being updated with the new values

Is it possible to retrieve data from a database and modify it using AJAX? I tried changing the input, but AJAX keeps sending the original data stored in the database. <script> function showMore(str) { var xhttp; if (str.length == ...

Incorporate an image into your webpage with the Fetch API by specifying the image link - JavaScript

I've been attempting to retrieve an image using the imageLink provided by the backend server. fetchImage(imageLink) { let result; const url = `https://company.com/internal/document/download?ID=${imageLink}`; const proxyurl = 'https:/ ...

Tips for effectively parsing extensive nested JSON structures?

JSON Data on PasteBin I need assistance in converting this JSON data into an Object. It seems valid according to jsonlint, but I'm encountering issues with parsing it. Any help would be greatly appreciated. "Data":[{...},{...},] // structured like t ...

I am encountering an issue where the key is not located in the response array in PHP, causing my JavaScript chart to remain

Hey there! I'm currently working on a school project and could really use some assistance. The task at hand involves creating a web interface that can interact with an endpoint in order to: - Authenticate a registered user to retrieve an authenticati ...

Using Javascript within HTML: A guide on when to utilize semi-colons and when to implement the return false statement

Exploring the use of JavaScript attributes within HTML elements: <input type="button" onclick="somceFunc()" /> <input type="button" onclick="somceFunc();" /> <input type="button" onclick="somceFunc(); return false;" /> Debating whether ...

Acquiring a document from Mongoose using Angular

After successfully uploading a file and storing it in my MongoDB, I now need to implement the functionality to download this file from the same MongoDB. On the server-side, I am utilizing the GridFS module in Mongoose for both upload and download operation ...

The importance of manually loading extensions and utilizing Ajax effectively for renderPartial

Within my yii application, I have implemented Tabs and am loading content via ajax using renderPartial(). To prevent redundant script loading, I have set processOutput to false. As a result, I aim to manually load all necessary scripts once on the index pa ...

Manually adjust rotation in Three.js by clicking

I am looking to initiate an animated rotation of an object by clicking a button. I have a basic understanding that the render function operates as an infinite loop and that adding 0.1 to cylinder.rotation.x continuously rotates the object. My goal is to ...

Separate string by using a regular expression pattern

Looking to parse a dynamic string with varying combinations of Code, Name, and EffectDate. It could be in the format below with all three properties or just pairs like Code-Name, Code-EffectDate, or Name-EffectDate. {"Code":{"value":"1"},"Name":{"value": ...

When an anchor tag is embedded within a string response, ReactJS fails to render it as a clickable link

I am in the process of transitioning our code from Freemarker to React JS and I am encountering an issue with rendering anchor tags from a JSON string response. When I display this string in my React JS application, the anchor tags are appearing as plain t ...

Specify that a function is adhering to an interface

Is there a way in Typescript to ensure that a function implements a specific interface? For example: import { BrowserEvents, eventHandler, Event } from './browser-events'; export function setup(){ const browserEvents = new BrowserEvents(); b ...

How can I correctly export my npm package?

I have successfully developed an npm package. class Person { constructor() {} sayHello() {console.log("Hello World!")} } module.exports = Person; Upon installing the package using npm i my-package, it was integrated into my project. ...

Access the JSON data containing sub array values and showcase them on an HTML page by utilizing ngFor

Greetings! I am currently working on a web application where I need to showcase student data that is being received in JSON format. Below is the TypeScript code snippet that outlines the structure of the student data: export interface studentData{ ...

React: The issue with async and await not functioning as expected when using fetch

I am working with an API on a Node server that returns JSON data like this: {"result":[{"ProductID":1,"ProductName":"iPhone10","ProductDescription":"Latest smartphone from Apple","ProductQuan ...

How can I utilize passed in parameters in Meteor React?

I am trying to figure out how to use two params that I have passed in the following example. Can someone please assist me? updater(layer, item){ this.setState({layer5: <img id="layer5" className="on-top img-responsive center-block" name="layer5" ...

Tips for displaying the number of selected values in a select box label (e.g. Choose an Option)

I am currently using the jQuery multiselect API in my application to allow users to select multiple values. However, I am facing an issue where I need to fetch all the selected values when a button next to the multiselect box is clicked. Unfortunately, I h ...

Receiving error message "[object Object]" while working with JavaScript

My current challenge involves adding an item to the shopping cart through a button click event that sends necessary data to a database table storing cart items. The issue arises with the item name, as I am encountering an error displaying [object Object] ...

What steps should I take to successfully install using npm if I keep encountering the same error?

Every time I attempt to install a package using npm, I encounter the following warning: npm WARN EBADENGINE Unsupported engine { npm WARN EBADENGINE package: '<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="c7b3aeaba2b3be ...

Is it possible to have both Node.js and browser code in the same file using webpack, while ensuring that only the browser code is accessible and the Node.js code remains hidden?

I need to work with a file that contains both Node.js and browser code. It's crucial that the Node.js code remains hidden when running in the browser environment. Is it possible for Webpack to exclude specific sections of the code based on the enviro ...