AngularJS ng-repeat doesn't refresh following an Ajax request

I am using an AngularJS application where I have a chat feature on the right side for communication with my clients.

Here is the HTML code:

<div class="recent" ng-show="show_chat_list">
    <h2></h2>
    <div ng-repeat="customer in recent_customer_list track by $index" ng-click="start_chat(recent_client_id[$index])" class='user'>
        <a href="#" ng-class="{'red-background': notify[$index]}">
            <img ng-src="">
            <div class="user-data">
                <span class='name'> {{ notify }} </span>
                <span class='name'>{{ customer.name }}</span>
            </div>
        </a>
    </div>
</div>

To update the list, I use a factory that polls every second for new information:

factory('Poller', ["$http", "store", "URL", function($http, store, URL){

    var data = {
        "hairdresser_id": store.get("userId")
    }

    var poller = function(){
        return $http.post(URL.url + 'check_for_notifications', data).then(function(res){
            return(res.data);
        });
    }

    return {
        poll: poller
    };
}]);

In the controller:

pollData();

function pollData(){
    Poller.poll().then(function(res){
        $scope.recent_customers_list = res.customers;
        console.log($scope.recent_customers_list[0].name);
        $scope.recent_client_id = res.clients_id;
        $scope.notify = res.notify;
        $timeout(pollData, 1000);
    });
}

The issue I am facing is that even though the console log displays the correct name, the changes are not reflected dynamically in the client list displayed in the HTML (for example, when changing names or adding a client).

When I try to insert

$scope.$apply();

or

$scope.$digest;

right before the $timeout line, I receive the error:

Error: [$rootScope:inprog] $digest already in progress

If I place apply right after the function line pollData() and before Poller.poll(), I get this error:

Error: [$rootScope:inprog] $apply already in progress

However, my list still does not update. I have to refresh the page to see the changes. How can I resolve this issue?

Answer №1

Within your controller, the variable being utilized is

$scope.recent_customers_list

However, in the corresponding HTML file, you are referencing

recent_customer_list

This appears to be a minor typing error that needs correction.

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

How to Insert JSON into React Component's Attribute?

I am struggling with setting the value of a React component using JSON in the attribute. I want to concatenate a letter or word, but it doesn't seem to work. Is there a correct way to combine strings within a Component's attribute? In this case, ...

Retrieve the current row by clicking the button

I've been struggling to retrieve a specific value from a row displayed on my PHP webpage. My objective is to obtain the current value from a particular cell in the row, but using getElementsByTagName has not been successful as it only returns an HTMLC ...

Steps to create a pop-up displaying a unique message ID retrieved from my database

My goal is to implement a pop-up message dialog on my website. When a user clicks on a reply icon, a pop-up message will appear with a textarea for the user to respond to a question they have been asked. The current issue is that clicking on the tag alway ...

Choose the div element by its id with vanilla JavaScript instead of using the jQuery $ selector in order to utilize the RaphaelJS

Currently, I am utilizing the RaphaelJs' mousedown() method. However, I am encountering a problem as I wish to apply mousedown() on a div that is selected using the $(id) selector of JQuery. In this case, I prefer to use vanilla Js for performance rea ...

Using Jquery to attach an event to a particular div which is part of a group of divs sharing

I am trying to implement a mouseup event on a series of divs that, when clicked, will reveal a child div ('menu'). All the parent divs have the same class. Here is an example: <div class="container"> <div class="menu"><p>Text ...

Mastering the art of square bracket destructuring in React through deep comprehension of the concept

import React, { useEffect, useState } from 'react' import { Text } from 'react-native' export default function Counter() { const [count, setCount] = useState(0) useEffect(() => { const id = setInterval(() => setCount((co ...

Does the current protected route that I am on restrict the user from navigating back to the Home component?

I'm having trouble figuring out how to redirect the user to the Home component when they logout. The API is functioning correctly based on my tests. However, I am unsure of how to implement the logout method in the current context to successfully log ...

My div is currently being concealed by a jQuery script that is hiding all of its

Below is the current code snippet: jQuery(document).ready(function($) { $("ul.accordion-section-content li[id*='layers-builder'] button.add-new-widget").click(function() { $("#available-widgets-list div:not([id*='layers-widget']) ...

my initial attempt at using Firebase cloud functions

I'm currently attempting to create my first Firebase Cloud Function. My goal is to take the value of the 'name' field from the 'amr' document and add it to the 'ahmed' document under a new field called 'newName' ...

Utilizing Ajax to dynamically update the color of a button when it is clicked from a different device

Currently, I am developing a program for my own use within my local community theater. The setup will involve a computer in the control room (Sound Booth) and another computer backstage. My plan is to create a grid of around 10 interactive "buttons" on th ...

Creating an empty array within an object in JavaScript

Consider the following scenario: var form = { header: { value: null, isValid: false, type: 'textinput', rules: { isRequired: true, ...

Exploring i18nNext integration with antd table in React

Presently, this is the UI https://i.stack.imgur.com/CMvle.png App.tsx import "./styles.css"; import MyTable from "./MyTable"; export default function App() { const data = [ { key: "1", date: "2022-01- ...

Tips for serializing a form using ajax for database storage in Laravel

Need help with saving multiple input fields to a database using AJAX. Here's the issue, I'm having trouble sending a serialized form to my database. When I serialize the form, attach it to a hidden input field using JQuery, and send it along wit ...

No response received when sending AJAX request from PHP to Node.js

Recently, I encountered a situation where I needed to send data from my php page to my node.js server and receive a response from it. Below is the ajax code snippet that I used to send the data from my php page, which was running on an Apache server: fun ...

Dropping challenging shapes in a block-matching game similar to Tetris

I'm currently working on a game similar to Tetris, but with a twist. Instead of removing just one line when it's full, I want to remove all connected pieces at once. However, I've run into a roadblock when trying to implement the hard-drop f ...

How to effectively leverage useMediaQuery in material ui?

Upon completing the web application, I have made the decision to ensure it is mobile-friendly. Utilizing the material UI framework with react, I delved into the documentation but found myself uncertain about how to effectively implement it. Let me provide ...

The browser is unable to access localhost:3000

Backend: Utilizing an Express server, created with the npx create-express-api command Frontend: Using Next.js, set up with npx create-react-app in the frontend directory Having executed these commands in the root folder, I attempted to run npm start xxx ...

When attempting to toggle the view on button click, it is not possible to select a shadowRoot

I am facing an issue with my parent component named ha-config-user-picker.js and its child component called edit-user-view.js. Parent Component: It contains a mapping of users and includes the child component tag along with its props. When a click event i ...

Adding an image to a Select Option label in React: A simple guide

As a newcomer to React, I am experimenting with creating a drop-down menu that includes images in the labels. My approach involves using a function to gather values from a map and construct an id: label pair to display as options in the drop-down. Both the ...

Node.js and Express facing challenge with Stripe checkout functionality

I am encountering an issue while attempting to integrate stripe into my checkout process. When I click on the checkout button, instead of being directed to the checkout page, I receive the following message: {"url":"https://checkout.stripe.c ...