Angular: What methods can I utilize to prevent my $http requests from causing UI blockage?

The following code snippet is from my controller:

PartnersService.GetNonPartnerBanks().success(function (data) {
        vm.nonPartnerBanksList = data;
    }).error( function () {
        vm.nonPartnerBanksList = [];
    });

This code calls the service shown below:

service.GetNonPartnerBanks = function() {
            var nonPartnerBankUrl = config.baseUrl + 'public/nonPartnerBanks';
            return $http.get(nonPartnerBankUrl);
        };

Everything functions as expected, however, if the server response takes too long, the application's user interface freezes.

I am puzzled - doesn't the $http service utilize AJAX and promises to allow the UI rendering to continue while the call is in progress?

Below is the part of the template that utilizes the retrieved data:

<ol class="nya-bs-select nya-dashboard"
    required
    name="futurePartner"
    id="futurePartner"
    ng-model="npc.futurePartner"
    data-size="5"
    ng-change="npc.hideSucessMessage()"
    title-tpl="<span>{{npc.partnerSelectTitle}}</span>"
    deep-watch="true"
    no-search-title-tpl="<span>{{'general.NoSearchResult' | translate}}</span>"
    data-live-search="true">
    <li nya-bs-option="bankItem in npc.futurePartnerList" data-value="bankItem.id">
        <a>
            {{bankItem.name}}
        </a>
    </li>
</ol>

Update:

After reviewing Vita's explanation, I realized that it wasn't $http causing my UI to hang. The issue was actually due to an animation on ajax calls giving the impression of a frozen UI.

Answer №1

HTTP calls are asynchronous, returning a promise that can be handled using .then and .catch as usual (success and error callbacks are depreciated).

Even with this, the UI isn't blocked by them. There must be another reason for the issue.

What exactly does "freeze" mean?

Where is the method being called from? Are you using it in the route object resolve attribute? If so, the feature of the route object is to wait for all promises to be fulfilled.

The definite problem lies elsewhere. Can you provide more information or share a JSBin for better assistance?

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

Leveraging AngularJS to Connect Controller Functions with Service Attributes

Just dipping my toes into the world of ngJS. I've managed to successfully bind the service objects to controllers. Is this the best way, or is there a more recommended approach? I'm also curious why this functionality seems limited to objects ...

Effortlessly implementing interactive form fields in Rails using jQuery

I'm struggling with implementing dynamic form fields in Rails. It seems that the framework does not handle this very smoothly, and I'm also incorporating jQuery into my project. While I have jRails installed, I prefer to write AJAX code unobtrusi ...

Fill the second dropdown menu options based on the selection made in the first dropdown menu

I need assistance with dynamically populating my second drop-down menu based on the selection made in the first drop-down. Here are the steps I've taken so far: form.php - Utilizing javascript, I have set up a function to call getgeneral.php. The se ...

Select a random character from a string using JavaScript

This question sets itself apart from Removing random letters from a string as it focuses on selecting a random letter from a string in JavaScript without removing any characters. The goal is to implement a code that picks random letters from a string in J ...

Preventing the default behavior using event.preventDefault() does not seem to be effective when submitting a

Why is the event.preventDefault() method not functioning properly? <script type="text/javascript" src="vue.js"></script> <div id="app"> <form v-on:submit.prevent="saveData"> <input type="text" name="test"> <button ...

Exploring a section of a react-chartjs Pie chart

I'm currently exploring how to create a static Pie chart using react-chartjs-2. Wanting to make one slice stand out more than the others, I aim to have it appear larger: My focus is on accessing a specific slice in the pie chart and adjusting its out ...

Using the then() function in the REST model does not support $http.get operation

With the recent deprecation of the http.get.success,error functions in Angular, using these calls in your controller is no longer recommended. Here is an example of the old code: $http.get("/myurl").success(function(data){ myctrl.myobj = data; })); T ...

Developing interactive checkboxes for individual rows through React.js

Within a form, I have rows containing two inputs each. Upon clicking "add", a new row is created. For the second row onwards, by clicking "add" a checkbox labeled 1 should be added to indicate dependency on the previous row. In addition, for the third row, ...

Issue with displaying value from page in AngularJS modal when clicked

How can I get the data copied from my page's $scope element (thisRequest) into my modal's $scope element (nTask) to display correctly in the modal after clicking a button in AngularJS? You can view the code on this Plunker. Here is an example o ...

Tips on creating a personalized memoizeOne function that delivers the accurate data type

I've implemented a function for object memoization: import memoizeOne from 'memoize-one'; type ArrayWithOneObj = [Record<string, unknown>]; const compareObject = ([obj1]: ArrayWithOneObj, [obj2]: ArrayWithOneObj) => obj1 === obj ...

Display drop-down item when selected for the first time and hide it when selected for the same item for the second time

Is there a way to display form input when "C" is selected and hide it when "A", "B", or "D" are selected? If "C" is selected again after initially showing the form input, should it be hidden? For example, if "C" is selected for the first time, the form inp ...

Can Sequelize be used to perform queries based on associations?

I have designed a data structure that includes an n:m relationship between "Rooms" and "Users." My current goal is to remove or delete a room. To accomplish this, I need to verify if the user initiating the deletion process is actually present in the room ...

Hide the 1, 2, 3 page buttons in Datatables pagination and instead display only the Next and Previous buttons for navigation

I recently implemented datadables.net pagination for my HTML table. I am looking to customize the pagination buttons by hiding or removing the 1, 2, 3 ... buttons and only display Next and Previous Buttons. Is there a way to achieve this by setting paging ...

Sharing data within angularJS applications can provide numerous benefits and increase

As a beginner in angularJS, I find myself still grappling with the concept of data sharing among various components like controllers, directives, and factories. It seems there are multiple methods available for facilitating communication between them -- ...

What could be causing my array to update when the method is called live but not during unit tests?

One of my methods is called toggleSelect which adds and removes items from an array named selectedItems. This method functions perfectly when I test it live in the browser. However, when running unit tests, it does not seem to work as expected. Despite cal ...

Executing a function by clicking on an element with the `ng-click` directive within a Bootstrap modal

I'm working on an app that allows users to submit posts for review. When a user clicks the add post button, I have a Bootstrap modal pop up to confirm their choice. Within this modal, there is a "confirm" button that should trigger a function. Strang ...

Setting an Element's attribute is only visible in the console

Just dipping my toes into the world of Web Development. While playing around with some JavaScript within HTML, I decided to try updating the content of an element. Upon running the code below, "Updated Content" appears in the console as intended. However, ...

Display pie charts on a Google Map

Utilizing a combination of JavaScript and GoogleMaps technology Within my application, there exists a screen showcasing a Google Map. In addition to this map, I have incorporated statistics detailing Population growth data displayed in the form of Pie Cha ...

What is the best way to display images when a single element in a list created by ngFor is hovered over in Angular 2

displayStar(val) { this.starDisplayed = true; } <ul class="listboxtickets"> <li class="selectlistticket" *ngFor="let item of ticketList" (mouseover)="displayStar(item.id)" (mouseleave)="hideStars()"> <div class="ticket ...

Karma: Uncaught ReferenceError - You must define the app before using it

I recently followed a tutorial on for testing AngularJS applications with Karma. This is how my karma.conf.js file appears: module.exports = function(config) { config.set({ basePath: '', frameworks: ['jasmine'], files: ...