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

Experimenting with a Jest test on an express middleware

I'm currently faced with a challenge in testing my controller (express middleware) using Jest. To better illustrate the issue, I will share the code snippet below: import request from 'utils/request'; import logger from 'config/logger& ...

How to set the chosen option in a dropdown using AngularJS

I'm populating a dropdown menu with an array of different 'types'. When a user chooses an option from the dropdown, I store that selection in a cookie. Here is the code snippet where I update the ng-model: $scope.typeItem = $cookieStore.ge ...

Implement the AngularJS orderby filter based on a checkbox selection

Is it possible to use the angularJS orderby filter with a checkbox for ordering columns? I currently have this working as expected: <tr ng-repeat="player in players | orderBy:'id':true | rangeFilter:min:max"> <td>{{player.id}}</ ...

The extent of utilizing the click handler in ECMA script 6

In ES6 arrow functions, the scope of this becomes available. However, there are instances where I cannot access this in an arrow function while it works with a normal anonymous function. For example: Sample 1 $(document).ready(function() { $(' ...

Is it possible to generate a Token in Nexus for private packages without using the UI interface?

We have implemented Sonatype Nexus Repository ManagerOSS 3.29.0-02 and are currently facing an issue in generating a TOKEN that can be used with .npmrc following this specific structure: registry=http://NEXUS-IP:8081/repository/GROUP-NAME http://NEXUS-IP:8 ...

Ways to verify if a variable holds a JSON object or a string

Is it possible to determine whether the data in a variable is a string or a JSON object? var json_string = '{ "key": 1, "key2": "2" }'; var json_string = { "key": 1, "key2": "2" }; var json_string = "{ 'key': 1, 'key2', 2 } ...

What is the best method to retrieve a nested JSON property that is deeply embedded within

I am facing an issue with storing a HEX color code obtained from an API in a Vue.js app. The object app stores the color code, for example: const app = {"theme":"{\"color\":\"#186DFFF0\"}"}. However, when I try to access the color prope ...

What is causing the list-sorter to malfunction?

This website crashes when executed: <head> <script> var numbersList = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 19, 17, 15, 13, 11, 9, 7, 5, 3, 1]; var orderedList = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, ...

Issue with Bootstrap Nav Dropdown in Yeoman Gulp-Angular configuration

I recently built an Angular App using the Swiip/generator-gulp-angular framework and ran into some issues when trying to implement a bootstrap nav dropdown menu. After searching for a solution, I came across this helpful Stack Overflow thread: Bootstrap D ...

Need a jQuery callback function in PHP that only retrieves the value without any redirection

Initially, I expected this task to be simple but it turns out my skills are a bit rusty. The snippet of javascript/jquery code that I am using is: $.get("plugin.php", {up_vote:surl}, function(data){ //alert(data); document.getElementById(&apo ...

Tips for executing specific javascript on small screens or mobile devices

I am currently in the process of developing a Vue web application that needs to be functional on all devices. I have certain code that should only run on small screens or mobile devices. Right now, I am using an if statement with $(window).width() to achie ...

Designing websites using elements that float to the right in a responsive manner

Responsive design often uses percentage width and absolute positioning to adjust to different screen sizes on various devices. What if we explore the use of the float right CSS style, which is not as commonly used but offers high cross-browser compatibilit ...

Issue with Angular modal text boxes failing to populate using ngModel

I am facing an issue with populating data in a modal when a table row is clicked. The table contains TV show data and uses dir-paginate/ng-repeat to display the information. However, when I click on a row to edit the show, the ng-model data does not load i ...

My goal is to implement a confirmation modal prior to any route changes within Next.js framework

Below is the code block that I have: const onRouteChangeStart = React.useCallback(() => { if (formState.isDirty) { if (window.confirm('Confirmation message')) { return true; } NProgress.done(); throw "A ...

Move the menu button to the right of the title slide, beyond the edge of the card

Having an issue with the MuiCardHeader component. <CardHeader disableTypography avatar={renderAvatar()} action={ <IconButton onClick={toggleMenu}> <img src={MoreIcon} alt=""/> </IconButton ...

Firebase issue: The function ref.once is throwing an Uncaught TypeError and is not recognized

I am attempting to utilize Firebase for both uploading a file and storing it in my database simultaneously. I want to track the number of uploads so that I can rename each file uniquely. While I have successfully uploaded and stored a copy in the database, ...

Is `h` equal to `createVNode` function?

Both h and createVNode are exposed from vue. The documentation on this page seems to imply that they are interchangeable: The h() function is a utility to create VNodes. It could perhaps more accurately be named createVNode(). However, replacing h with ...

Guide on selecting every input field located within a table

My form is embedded within a table <form id="form"> <input type="submit" value="send" class="btn btn-w-m btn-primary" style="float: left;">Add transaction</input> <table class="table table-strip ...

Using localStorage in Next.js, Redux, and TypeScript may lead to errors as it is not defined

Currently, I am encountering an issue in my project where I am receiving a ReferenceError: localStorage is not defined. The technologies I am using for this project are Nextjs, Redux, and Typescript. https://i.stack.imgur.com/6l3vs.png I have declared ...

Encountered a problem during the insertion of data into the database through ajax and php

An issue is being encountered while trying to insert data into a database using Ajax, PHP, and jQuery. The code works smoothly on a localhost environment, but upon uploading it to the server, an error occurs. $('#sunsubmit').click(function(){ ...