Experiencing excessive delay in loading data into the DOM following a successful response from a service in AngularJS

I am facing a challenge in loading a large set of data into an HTML table.

  1. To begin, you need to click on a button:

    <a ng-click="get_product()">load data</a>
    
  2. This button triggers a function called get_product:

    $scope.get_product = function () {
      // display loader image
      var get_product = PAYMENTCOLL.getStatusBasedPaymentCollection(); //service call
      get_product.success(function (data)
      {
        $scope.pagedItems = data; //store data in an array
      });
      //hide loader image after loading
    };
    
  3. The pagedItems array is then loaded into the HTML table using ng-repeat.

Scenario 1:

If the dataset is small, the loader image will hide once all data is loaded into the DOM.

Scenario 2:

For larger datasets, the loader image hides early but the data continues to load into the DOM (taking around 3-4 seconds more).

Purpose:

My goal is to keep the loader image displayed until all data is fully loaded into the DOM. Once everything is loaded, I want to hide the loader image.

How can I address the issue in Scenario 2? Thank you in advance.

Answer №1

Have you thought about implementing promises?

Consider using $q promise to handle the fulfillment of setting $scope.showLoaderImage.

$scope.get_product = function () {
    $scope.showLoaderImage = true;
    PAYMENTCOLL.getStatusBasedPaymentCollection().then(function (e) {
        $scope.showLoaderImage = false;
        $scope.pagesItems = e.data.d;
    }, function (err) {
        //Deal with Errors
    })
};

To update the status of $scope.showLoaderImage in your DOM, utilize ngShow, as demonstrated below:

<div ng-show="showLoaderImage">
   <!-- Placeholder for Image -->
</div>

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

Issue with manipulating element styles using jQuery in Angular2

My method of assigning IDs to elements dynamically using *ngFor looks like this: <div *ngFor="let section of questionsBySubCat" class="col-md-12"> <div class="subcat-container"> <h4 class="sub-cat">{{ section?.subcategory }}& ...

Issues with JQuery .on() occur when functions are passed as arguments

There seems to be a difference in how the .on() function behaves when passing functions as parameters. Interestingly, defining the function inside the parameters versus passing it separately can have different results. An example of this discrepancy is de ...

The Angular model finally refreshes its values after a console.log() is executed

UPDATE After further investigation, I discovered that the issue was not related to Angular itself, but rather a mistake in the update function within the node server controller. I have provided the fix below for reference, and decided to keep this questio ...

Troubleshooting Problem with JQuery in the YouTube Player API

Having some difficulty parsing YouTube video ids to a function that plays them in an embedded player using a combination of JavaScript and jQuery with the YouTube Data and Player APIs. Below is my code: <html> <head> <script src="//aj ...

Sending a document through the input field with React Hook Form

In my application, I have implemented a file input to submit a file and send it to a firebase storage bucket. To achieve this functionality, I am utilizing the react-hook-form library. However, I encountered an issue - I wanted the file to be uploaded with ...

Steps to Export Several Fusion Charts into Individual Image Files

My webpage contains multiple charts created using the Fusion Chart library. There are three different charts on the page, and I want to export each chart as a separate PNG file. However, when I click the export button, it generates separate images of the ...

Tips for changing the background with a jquery slider

Using a jquery slider, I have a single layout with a center div for content. I am trying to change the color of the layout as I slide to a different page. This is for an ASP.NET MVC3 project. HTML: <div id="iPhone_Product"> <div class="s ...

Multiple web pages utilizing Angular app/widget

I have successfully built a chat application similar to Google Hangouts. However, I am facing a challenge with the angular app/widget running on other pages when URL's are changed, causing the app to either remain fixed or restart on the new web page. ...

Troubleshooting a labeling problem in a donut chart with Chart.js

$(document).ready(function(){ function call() { $.ajax({ url: "chartjs/tempdata.php", method:"GET", cache: false, success: function(data) { console.log(data); var difference=[]; var percentage=[]; var finaldata=[]; for(var i in data) { //time.push( ...

Utilizing JQuery and AJAX to fetch a specific variable

Hey there, I'm new to jQuery and AJAX. I've been attempting to pass a value from page 2 to page 1 using this script, but it doesn't seem to be working properly. Check out the script: function prova() { var parametro = $("#nome_priv ...

"React-router is successfully updating the URL, however, the component remains un

I am currently working on a React application that includes a form for users to fill out. Once the user clicks the submit button, I want them to be redirected to a completely different page. Although I have only focused on the visual design at this point a ...

Arranging a javascript object by organizing an array as a value

Looking to organize a JavaScript Object structured as key:pair, where the pair consists of an array with 2 timestamp values. The goal is to arrange the elements so that those with the smallest numbers (earliest times) are shown first. For instance, consid ...

Incorrect pathing in express.js

I've encountered an issue with my filter while attempting to redirect packages using two express.js routes: app.get('/billdetails/:year/:month/:phoneId', function (req, res, next) { var db = req.db; var year = req.params.year; v ...

After generating the token, where is the appropriate place to define the authorization header?

I am currently working on implementing a security system based on tokens. The challenge I am facing is determining the appropriate location to set the authorization header after generating it, in order to validate it across all of my different routes. Belo ...

Processing Data with JavaScript

I am new to working with JavaScript, coming from the Python world. I need some assistance. Currently, I am retrieving data from the back end that has the following structure: { "Airports": { "BCN": { "Arrivals": [ ...

Dynamic drop-down navigation with rearranging menu

I am attempting to design a drop-down navigation bar with 2 rows. Initially, only 1 row is visible. Upon clicking the visible row, both rows should appear. Subsequently, when one of the 2 rows is clicked, only that specific row should be displayed. Below a ...

What causes the Invalid Form Body error to appear when using the Discord API?

While developing a Discord bot, I encountered an issue with creating a ping command. The error message received was as follows: (node:37584) UnhandledPromiseRejectionWarning: DiscordAPIError: Invalid Form Body embed.footer.icon_url: Scheme "flashybot& ...

Transferring class titles between div elements

I would like to implement a feature where class names on div elements shift after a brief delay, perhaps 10 seconds. My goal is for the 3 classes listed below to cycle through the div elements and start over once it reaches the last one. For instance: & ...

Enhancing angular-schema-form with a unique custom type for datepicker functionality

I'm attempting to integrate a custom type into angular-schema-form for the ui-bootstrap datepicker. After following the provided instructions, the field is not being rendered when I open the form. The module I have loaded on the page: angular.modul ...

Abrupt surge in Firestore read operations detected in Next.js application following a period of no modifications - refer to the accompanying visual

https://i.sstatic.net/vim7m.png During the initial 10 days of working on the project, I noticed a consistent range of reads between 100 - 300 per day while regularly refreshing documents from firestore. Days 11-15 were spent away from the project visiting ...