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

Looking to trigger a PHP page by clicking on a div?

Is there a way to trigger a PHP page call when a user clicks on a <DIV> with AJAX? Additionally, can the text of the DIV be changed to display "LOADING....." simultaneously? I lack knowledge about AJAX. Could you please provide me with more details ...

Creating a parameterized default route in Angular 2

These are the routes I've set up: import {RouteDefinition} from '@angular/router-deprecated'; import {HomeComponent} from './home/home.component'; import {TodolistComponent} from './todolist/todolist.component'; import { ...

Expand the table in the initial state by using CSS to collapse the tree

I am struggling to collapse the tree view and need assistance. Below is the code snippet I've added. My goal is to have each node in the tree view initially collapsed and then expand a particular node on user interaction. For example, when I execute ...

The art of concealing and compressing JavaScript code

Can modern JavaScript obfuscation and minification tools effectively protect my code from reverse engineering? Which obfuscation platforms are the most reliable in thwarting these attempts? Is it possible that a program could easily deobfuscate the code, ...

Utilizing GeoLocation in JavaScript: Implementing a Wait for $.ajax Response

Whenever I make an AJAX POST request to my backend server, I aim to include the latitude and longitude obtained from the navigator. However, it seems like the request is being sent in the background without waiting for the navigator to complete its task. ...

Executing certain test suites with defined capabilities in Protractor

My website is designed to be compatible with both desktop and mobile browsers, each having its own unique user interface. In my protractor config file, I have some suites that need to be tested using the desktop user agent, while others require testing usi ...

The back-to-top button guides users back to their last visited page

I'm excited to explore AngularJS and I want to add two "return to top" buttons on different pages. Here's what I have so far: Page 1: <h1 id = "top"> .......... <a href="#top" target = "_self">Return to Top</a> Page ...

24-hour countdown tool featuring a visual progress bar

Currently, I am in the process of developing an application aimed at assisting individuals in either forming new habits or breaking old ones. In this application, I am looking to implement a countdown timer that ticks down daily; with the help of this help ...

Customizing order and limit features in AngularJS

I have a collection of items that I need to organize into separate lists based on priority levels. items = [ {'type': 2, 'priority': 1, 'name': 'one'}, {'type': 1, 'priority': 2, 'na ...

Configuration object for Webpack is not valid

I encountered an error while using webpack that says: Invalid configuration object. Webpack has been initialized with a configuration object that does not conform to the API schema. - configuration.resolve has an unknown property 'extension&ap ...

Is there a way to make a table row clickable? I tried finding solutions online, but none of them seemed to work for me

Having trouble opening a new page when tapping on a cell (TR) using Javascript. Despite trying various online tutorials, I still can't get it to work properly. Any assistance would be greatly appreciated. Thank you. Below is the code snippet: fun ...

How to address additional attributes received from the server in Next.JS

Encountering an error while trying to render a canvas with specified height and width within a child component in a NextJs app. The issue arises when attempting to integrate this mouse effect into my NextJS application. Everything functions correctly until ...

What is the best way to set the width of a w2grid to 100%

Has anyone tried using w2grid before? I'm having trouble figuring out how to make it fill its container 100%. Here's the HTML snippet: <div id="a" style="width:100%"> <!-- top left container--> <div>This ...

problems encountered when including next.config.js for sitemap creation in a nextjs application

Just recently, I made an update to my next.config.json file in hopes of boosting SEO performance. However, this change has caused some issues with the next-sitemap module, preventing me from building or starting my app. //next.config.js const withSitemap = ...

Exploring AngularJS for real-time updates from a persistent database

Hello, I'm new to Angular and currently working on an app that requires frequent polling of a URL every second. The retrieved data needs to be stored persistently for access across multiple views and controllers. To handle this, I've placed the ...

Error message displaying "Invalid ID attribute in HTML 5 input"

On my website, I have a page with multiple items, each containing an HTML5 input field. Whenever a user changes the value of the input, it triggers an AJAX call to the server. The server then responds with JSON data, including an array of items that have ...

Guide to making a toggle button with a Light/Dark mode functionality

I have implemented a light/dark toggle button and now I want to integrate the functionality for switching between light and dark themes on my webpage. The switch should toggle the theme between dark and light modes when clicked. Some basic styling has been ...

Utilizing UTC Time with AngularUI's UI-Date Datepicker

My issue lies with the datepicker using localized time instead of UTC when making calls to the backend. To handle this, I've created a function that adjusts the value before posting it to the server: function adjustDateForTimeOffset(dateToAdjust) ...

Routes inoperative as intended

When using a standard expressroute for this login, I have noticed that even if the req.body.password is incorrect, I am still getting redirected to '/login'. router.post('/student/login', (req, res) => { if (req.body.password === ...

Angular 4 applications do not come with TinyMCE embedded

I've been attempting to integrate the tinyMCE editor into an angular4 application, but unfortunately I encountered an error that reads: tinyMCE is not defined. https://i.stack.imgur.com/qMb5K.png I have been following the guidance provided by tin ...