What are the different ways to utilize the Angular Loading Bar for specific waiting scenarios?

In the project I am currently working on, navigation is primarily done through Ajax loading of HTML templates. The Angular Loading Bar feature is proving to be quite effective in this setup, as it employs interceptors to keep track of most $http requests. What's interesting is that it also includes start() and complete() methods which function exactly as I need them to - initiating and stopping the loading indicator without being dependent on any specific $http request.

However, I am facing a challenge in trying to access this service either directly or by injecting it into a controller in order to utilize these two essential methods. The only mention of this service can be found at the beginning of the Angular app:

var MlamAngularApp = angular.module('MlamAngularApp', ['kendo.directives', 'ngRoute', 'angular-loading-bar', 'ngAnimate']);

MlamAngularApp.config(['cfpLoadingBarProvider', function (cfpLoadingBarProvider) {
    cfpLoadingBarProvider.includeSpinner = true;
    cfpLoadingBarProvider.includeBar = true;
}]); 

This is followed by numerous declarations of services, factories, and controllers such as:

MlamAngularApp.service('QuoteService', QuoteService);
MlamAngularApp.factory('ApplicationCancelFactory', ApplicationCancelFactory);
MlamAngularApp.controller('MlamController', MlamController);

I have a feeling that the Loading Bar should be included somewhere within these declarations, but I am unsure of where or how to do so.

Answer №1

Indeed, by injecting cfpLoadingBar into the controller, you can gain access as indicated in your speculation. The code snippet below demonstrates how to manually start and end loading, while also configuring the loading spinner and bar using the provider.

var app = angular.module('app', ['angular-loading-bar']);
app.config(['cfpLoadingBarProvider', function(cfpLoadingBarProvider) {
    cfpLoadingBarProvider.includeSpinner = true; // Display the spinner.
    cfpLoadingBarProvider.includeBar = true; // Show the loading bar.
}]);
app.controller('appCtrl', ['cfpLoadingBar', function(cfpLoadingBar) {
    cfpLoadingBar.start(); // Start the loading process.
    setTimeout( function() {
        cfpLoadingBar.complete(); // Finish loading.
    }, 1000);
}]);
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/angular-loading-bar/0.7.1/loading-bar.min.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular-loading-bar/0.7.1/loading-bar.min.js"></script>

<div ng-app="app" ng-controller="appCtrl"></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

Display the initial page and activate the first navigation button when the page loads

Greetings to everyone. I am new to the world of jquery and currently in the process of learning. This is my script: <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.0.0/jquery.min.js"> </script> <script> $(function () { $ ...

Remove the most recent row that was dynamically inserted into an HTML table

Currently, I am in the process of developing an ASP.NET Web Api 2.2 application using .NET Framework 4.5, C#, and jQuery. Within one of my views, I have set up the following table: <table id ="batchTable" class="order-list"> <thead> ...

Disregard validation of the view if the element includes the attributes `display: none`

Displayed below is an HTML text input that is designed to toggle visibility using jQuery's slideUp and slideDown functions, which change the display attribute to none with animation. My current challenge is that I do not want to validate the element w ...

Utilize Twilio to forward messages to a different phone number

I am seeking a solution to automatically forward incoming messages from one Twilio number to another, based on the original sender's number. For example: If I receive a message on my Twilio number "+14444444444" from '+15555555555', I want ...

Can we pass a search term parameter to getServerSideProps in Next.js?

I've been working on a project to organize all my notes and summaries in one place. The notes are stored as markdown files, converted to HTML dynamically in the backend (it's functioning well). Now, I want to add a search feature on the notes p ...

The value of the comment box with the ID $(CommentBoxId) is not being captured

When a user enters data in the comment box and clicks the corresponding submit button, I am successfully passing id, CompanyId, WorkId, and CommentBoxId to the code behind to update the record. However, I am encountering an issue as I also want to pass the ...

What sets apart route.use(), route.all(), and route.route() in Express?

Is it possible to replace router.all() with router.use() if the former just matches all methods? Also, what are the differences between using router.use() and router.route()? ...

Identifying instances where the AJAX success function exceeds a 5-second duration and automatically redirecting

Greetings! I have created a script that allows for seamless page transitions using Ajax without reloading the page. While the script functions perfectly, I am seeking to implement a feature that redirects to the requested page if the Ajax request takes lo ...

Unable to set background-image on Node (Limited to displaying only images sourced from Flickr)

I am experiencing difficulty with the background-image node property not functioning properly. In order to test this issue, I am using the "Images & breadthfirst layout" demo as an example (accessible at https://gist.github.com/maxkfranz/aedff159b0df0 ...

Techniques for adding values to arrays in JavaScript

My Anticipated Result let Album = { album_desc: AlbumTitle, id: 1, album_title: 'ss', AlbumDescription: 'sdsd', ImageName: 'image.jpg', album_pics: below array }; I am looking to dynamically p ...

What is the method for utilizing a filter to extract the specific value from the elements within an array of double objects?

I am facing an issue with my code where I have an array called pick containing objects and another object named diaryItem. My goal is to extract only the object with the name 'wormColor' from the diaryItem object. Unfortunately, when I tried run ...

Rails: The "link_to" method for logging out and deleting sessions is unresponsive

My app allows users to view blog posts once they are "signed up/ logged in" and saves their id in session[:user_id]. An issue I am facing is with the "link_to" method for logging out. When hovering over the "Logout" link in the browser, it doesn't ap ...

Tips for redirecting to a 404 page when encountering invalid data in getStaticProps

For my Next.js application, I need to retrieve all articles written by a specific author. The author's ID is obtained from the request parameters. I have already pre-generated some authors using getStaticPaths. Within the getStaticPaths function, I h ...

a beginner's guide to utilizing the grunt target

Here is an example of my Gruntfile.js: 'use strict'; module.exports = function(grunt) { grunt.initConfig({ grunt.config.set('targ', grunt.option('target')); cachebuster: { build: { ...

Adjust the size of a Div/Element in real-time using a randomly calculated number

Currently, I am working on a script that is designed to change the dimensions of a div element when a button on the page is clicked. The JavaScript function connected to this button should generate a random number between 1 and 1000, setting it as both the ...

What is the best way to utilize "require" dynamically in JavaScript?

Within the "sample.js" file, there is a JavaScript function structured as follows: var mapDict = { '100': 'test_100.js', '200': 'test_200_API.js', '300': 'test_300_API.js' } function mapAPI() { ...

Update a variable globally within setInterval function

Seeking assistance on showcasing the number of seconds that have elapsed using a setInterval function in JavaScript integrated within HTML. The code snippet below has been attempted, but it is only displaying 1 second and the test function appears to not ...

Utilizing Vue CLI's sourcemaps to pinpoint the styling within a Vue component file

Currently, I am working on a Vue CLI project. After setting up the project and making some development changes, my package.json file now includes: package.json "dependencies": { "bootstrap": "^4.3.1", "core-js": "^3.0.1", "preload-it": "^1.2. ...

Using backslashes to escape a JavaScript array elements

How can I modify the code below to properly escape HTML and strings in JavaScript arrays? I've been attempting to use a function called escapeHtml to add the necessary slashes, but it's not functioning as expected. Any help would be appreciated. ...

Issue with column pushing and pulling in Bootstrap

Despite thinking I understood how pushing and pulling columns work, it seems that I was mistaken. Here is a link to my very simple grid on jsfiddle. In the xs view, it looks like this: Insured Name Face Amount Gender Product Then in the sm view, it ch ...