"Caught in a limbo: Angular UI-Router struggling to navigate

In my current project, I am utilizing UI-Router and taking advantage of the state resolve feature it provides. However, I've encountered an issue where a loader spinner that is meant to display between states gets stuck and does not disappear when transitioning frequently between states.

A similar problem can be observed at this link: . When rapidly switching between states, the loader fails to hide properly.

I have set up listeners for various events like $stateChangeStart, $stateChangeSuccess, $stateChangeError, and $viewContentLoaded to manage the showing and hiding of the loader. Strangely, while $stateChangeStart triggers as expected, $stateChangeSuccess does not. This behavior has left me puzzled. Any thoughts on why this might be happening?

Below is the code snippet related to showing and hiding the loader:

    $rootScope.$on('$stateChangeStart', showLoading);
    $rootScope.$on('$stateChangeSuccess', hideLoading);
    $rootScope.$on('$stateChangeError', hideLoading);
    $rootScope.$on('$viewContentLoaded', hideLoading);

    function showLoading() {
        $timeout(function () {
            angular.element('.loading-indicator').show();
        }, 50);
    }

    function hideLoading() {
        $timeout(function () {
            angular.element('.loading-indicator').hide();
        }, 50);
    }

Answer №1

To stop the previous timer, you should refer to the instructions provided in the documentation at this link: https://docs.angularjs.org/api/ng/service/$timeout.

var customTimer;
function displayLoading() {
    if (customTimer) {$timeout.cancel(customTimer);}
    customTimer = $timeout(function () {
        angular.element('.loading-indicator').show();
    }, 50);
}


function hideLoader() {
    if (customTimer) {$timeout.cancel(customTimer);}
    customTimer = $timeout(function () {
        angular.element('.loading-indicator').hide();
    }, 50);
}

Answer №2

I fail to comprehend the necessity of using a timer for loading spinner animations, I suggest utilizing only CSS for such purposes.

Here is a snippet of my code: HTML

<div ui-view class="fade container-fluid"></div>
<div class="spinner modal-viewer" hidden>
    <div class="transparente"></div>
    <div class="contenedor">
        <div class="center-middle">
            <div class="sk-circle">
                <div class="sk-circle1 sk-child"></div>
                <div class="sk-circle2 sk-child"></div>
                ...
                <div class="sk-circle11 sk-child"></div>
                <div class="sk-circle12 sk-child"></div>
            </div>
        </div>
    </div>
</div>

To avoid losing control of the state controller and ensuring the spinner can be properly managed, it's advisable to place the spinner outside of the uiView element as shown in the example above.

JS

document.querySelector('.spinner')['style'].display = 'none';

I offer my sincere apologies for any confusion in my previous response.

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

(Build an Angular, TypeScript Application) Develop a new function using a string that includes an if statement without using the eval function

Is it possible to create a new function from a string that includes an if condition? The actual string will be provided externally, but for the sake of this example, everything is hardcoded. let f1: number = 1; let f2: number = 0; let condition: string ...

Tips on utilizing $watch in this context to ensure the API is activated prior to the Directive, incorporating ui-router

I am currently using a ui-router and I have a question regarding the resolve function. Is it possible to use resolve with the following state configuration: state: { url: "/summary", templateUrl: '../script/planSummary.html', co ...

Having trouble integrating Twilio into your Meteor app? Getting a ReferenceError that says "Twilio is not defined"?

Let me start by saying that I'm new to Meteor and Twilio, so it's likely that I've overlooked something simple. I'm utilizing the Twilio API bindings from this source in an attempt to send an SMS message within a Meteor.methods functio ...

How can I make the primary element subtly appear while keeping the secondary one hidden?

setInterval(function () { $(".story1").fadeOut(2000,function(){ $(".story2").fadeIn(2000, function(){ $(".story2").fadeOut(2000) }); }) }); I have created this code. The initial story displayed is story1, an ...

What could be causing my Bootstrap datepicker to malfunction?

A while ago, my Bootstrap datetimepicker component was functioning perfectly in my code. However, it has suddenly stopped working and I am seeking assistance to get it running smoothly again. Below is the HTML code snippet: <script src="https://cd ...

Render and download the file concurrently while displaying the view in Express

I'm looking to accomplish a task in Express where I can render a file and download it simultaneously. My current code looks like this: res.attachment('filename.csv'); res.render('pages/result', { data }); However, with this setu ...

Unable to retrieve array data using the post method in PHP and Angular.js

I am encountering a problem with my form submission using Angular.js and PHP. Despite sending an array of data to the server side using the $http service, I am not receiving any values on the server side. Below is an explanation of my code. var supplierDa ...

Guide on how to refresh the background image using the identical URL within a directive

I am looking to refresh the background image of a div using the same URL within a directive. Upon loading my view, I utilized this directive to display the image as a background for the div. app.directive('backImg', function () { var dir ...

Node.js seems to be having trouble with emitting events and catching them

I'm having trouble troubleshooting my code. // emitter.js var EventEmitter = require('events').EventEmitter; var util = require('util'); function Loadfun(param1, param2, db){ function __error(error, row){ if(error){ ...

In Node.js using Express, you can set up a validator to require a field only if another specific

Currently, I am utilizing express-validator to validate my post fields. However, I am facing an issue where I need certain fields to be required only if other fields have specific values. For example: If the person_organisation field is true: The person_o ...

Creating a dynamic Bootstrap carousel with a fixed hero header text inside a designated container - here's how!

I am currently working on a project to develop a responsive Bootstrap slider with a fixed hero header that remains consistent while the slider images change. The hero header needs to be aligned to the left within a responsive Bootstrap container and center ...

Merge jQuery with the jetpack infinite scroll feature

Utilizing the jQuery code below for an accordion effect on all my WordPress posts on the front end. (function($) { function initAccordion() { var $ele = $('.entry-content').hide(); $(".entry-header").unbind('click&apos ...

Display multiple values in a select dropdown using Bootstrap 5 properties

I am stuck with the following code<hr> HTML <select id="select" placeholder="Choose Select" class="selectpicker" multiple></select> <div class="container"> <div id="all" clas ...

Utilize the `addEventListener` and `removeEventListener` functions on the menu to

Why is my mobile menu not functioning correctly? The submenu should open on the first click and redirect to the parent URL on the second click, which works fine. However, when the window width increases to 768px or more, the submenu should appear on hover ...

Troubleshooting: Issues with the functionality of ng-include in AngularJS

Hi there, I am new to angular js and I'm attempting to integrate a simple html file into my page. Below is the code I am using: <!DOCTYPE html> <html ng-app=""> <head> </head> <body ng-controller="userController"> < ...

JHipster's Advanced Master-Detail User Interface

Can a master-detail form be created in JHipster? I have successfully generated two entities: Order Item (with many-to-one relationship to Order) Now, I am looking for a way to include CRUD operations for Items within the Order form. Any suggestions or ...

Vue select component not refreshing the selected option when the v-model value is updated

Trying to incorporate a select element into a Vue custom component using the v-model pattern outlined in the documentation. The issue at hand is encountering an error message for the custom select component: [Vue warn]: Avoid directly mutating a prop as i ...

What is the most efficient way to extract a key and its corresponding value from an object containing only one pair?

Currently, I am developing a recipeBox application using React JS. Within this application, there is a state defined as: this.state = { recipeArray: [] ...} Users have the ability to add recipes by pushing objects {recipe_Name : Ingredients} into tha ...

How to utilize a Jquery loop, implement a condition, and store the results in

After using dd() in PHP, the array displayed is as follows: 1 [▼0 => "1,18,187,188,189,190,191,192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,208,209,210,211,212,19,20,21,22,23,24"] I need to iterate through the array and o ...

Using Jquery to loop through various select options within a designated container div

I am seeking a way to loop through multiple select options within a specific div using the jQuery each function. If any field is left empty during this iteration, I would like the loop to break and set the reqCourseFlag variable to 0. The current implement ...