Is there a way to position the angular loading bar inside a specific 'div' instead of at the top of the page?

Recently, I integrated angular-loading-bar.js into my project to visually represent the progress of http calls. By default, the blue progress bar appears at the top of the screen. However, I wanted to customize it so that it would appear within a specific div on the page instead.

In a helpful answer, it was suggested to add the following line of code to activate the progress bar:

angular.module('app', ['angular-loading-bar']);

After adding this code, the progress bar continued to display at the top of the screen, rather than within the desired div. Upon inspecting the core angular-loadingbar.js file, I noticed that the progress bar was being inserted using the following lines:

this.parentSelector = 'body';
this.spinnerTemplate = '<div id="loading-bar-spinner"><div class="spinner-icon"></div></div>';
this.loadingBarTemplate = '<div id="loading-bar"><div class="bar"><div class="peg"></div></div></div>';

It's clear that the parent selector is set to body. Is there a way to dynamically change this parentSelector based on the page that is calling the loading bar?

Any assistance on this matter would be greatly appreciated. Thank you in advance!

Answer №1

To avoid using external libraries for a simple loader on the screen, one can create a DOM node at a preferred location and display it only when a specific flag in the $rootScope is set to true. For example:

<div class="my-custom-loader" ng-if="$root.loading">...</div>

Answer №2

How to Customize Template Positioning:

If you want to customize the position of the loadingBar or spinner, simply specify a CSS selector for the element where you want the template to be inserted. By default, it is placed within the <body> element:

angular.module('myApp', ['angular-loading-bar'])
  .config(['cfpLoadingBarProvider', function(cfpLoadingBarProvider) {
    cfpLoadingBarProvider.parentSelector = '#loading-bar-container';
    cfpLoadingBarProvider.spinnerTemplate = '<div><span class="fa fa-spinner">Custom Loading Message...</div>';
  }])


<div id="loading-bar-container"></div>

This information is sourced from the angular-loading-bar documentation available on Github

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

Getting just the outer edges of intricate BufferGeometry in Three.js

Currently, I am immersed in a project that involves zone creation and collision detection using Three.js. The primary objective is for my application to effectively manage collisions and produce a BufferGeometry as the final output. My aim is to visually r ...

Is it possible to use the .map() method on an array with only 3 items and add 2 additional placeholders?

I need to iterate through an array of 5 items in a specific way: list.slice(0, 5).map((i) => { return <div>{i}</div> }); However, if the array only contains 3 items, I would like to add placeholders for the remaining 2 items in my reac ...

Building a dynamic form in React: Fetching select data from an API, posting to another API, and automatically clearing fields upon submission

I am currently working on a form that utilizes a GET request to retrieve data from an API endpoint and then proceeds to make a POST request to another endpoint. Although I have been successful in achieving this function, I am facing challenges with reset ...

What can I do to prevent the border from breaking apart when I zoom in?

To address the problem of the 1px black border at the bottom of the header being cut off, try zooming into the page and scrolling right. How can this issue be resolved? ...

Forming a fresh array incorporating every single element from the subarray

I am looking to create a new array that consolidates all the parameters from the subarrays into a single resulting array. Explaining this with an example below: var myArr=[ { "Id":1, "Name":'Ken ...

Locally hosted website failing to transfer login details to external domain

Having trouble with an ajax call that is supposed to retrieve data from a web page, but instead returns a jQuery parse Error. Even though I can access the page directly, the ajax call doesn't seem to be working and storing the result properly. Below ...

Angular version 1.0.8 was resolved to angular 1.4.1 instead of 1.4.3

Incorporating both grunt and bower for dependency management in my project, I encountered an issue when trying to include an external library: https://github.com/ninjatronic/angular-base64 The hurdle I faced was its requirement of Angular #>= 1.0.8, w ...

I have been attempting to extract real estate listings from an MLS website using Beautiful Soup and have found some success. I am now considering if using Selenium would be a more efficient option

Perhaps this question has been answered before, which could help guide me in the right direction. The website loads 24 listings at a time and then displays a "see more results" button to load the next batch of 24 listings while keeping the initial 24 visib ...

Basic HTML code that displays either one or two columns based on the width of the screen

My monitoring website displays dynamic rrd graphs in png format with fixed dimensions. I am looking to adjust the layout based on browser window size - showing the graphs in 1 column if the width is below a certain threshold, and in 2 columns if it exceed ...

Combining JS Files

In our custom WP Theme, we incorporate Twitter Bootstrap, Font Awesome PRO (SVG), and JQuery. We are considering concatenating these .js files together in one minified file to reduce the number of page asset requests on load. Is there any concern with co ...

Creating a layout with cards positioned next to each other using Bootstrap

I have been trying to display these 3 cards side-by-side, but they always end up stacked on top of each other. Is there a specific code I need to add to fix this? <div class="col-md-4"> <div class="card rounded-lg" style="width: 17.5rem;"> ...

Transform Django Model Instance from Serialized Back to Object using Ajax

Currently, I'm utilizing Ajax to search for a model instance. Once found, I return that instance and pass it as a variable to a template tag within my template. To achieve this, in my view, I serialize the object before sending it to the Ajax success ...

The React live search functionality is operational, however, it is not effectively canceling previous requests in the

Currently, I am in the process of following a helpful tutorial over at "alligator.io". You can check out the specific link here: https://alligator.io/react/live-search-with-axios/ The code snippet below belongs to App.js: import React, { Component } from ...

What is the best method for utilizing dynamically assigned keys within a JSON object?

I am currently working with Rhino and I need to find a way to utilize a variable in order to define the key of a map. Here's an example of what I'm trying to achieve: var name = "Ryan"; var relationshipType = "brother"; var relatedName = "David" ...

Efficiently loading data using lazy loading in jsTree

I have been facing a challenge with dynamically loading the nodes of a jtree upon expansion. The limited documentation I could find is located towards the end of this specific page. Several solutions involve creating nodes individually using a loop, simil ...

The css values for component _nghost-c0 in an Angular application

Recently, I've been delving into Angular 5 and couldn't help but notice the peculiar html tags with ng generated attributes like _nghost-c0 and _nghost-c1... This got me wondering, what exactly do these attributes signify? [_nghost-c3] .employee ...

Display or conceal a div based on the input value

Displaying div#cool should be triggered when the user enters the term "cool" into the input field. Similarly, showing div#good should be activated when the user types "good", and this functionality should operate seamlessly in real-time. ...

CSS3 transition not functioning as expected

I am attempting to use CSS3 transition effects to change the background and text color when hovering over a button. However, only the text color is changing and not the background color. You can view my code on jsfiddle here. Here is the CSS I am using: ...

Exploring the functionalities of PointerLockControls, incorporating WASD controls, and experimenting with Three.js

Forgive me if this is a beginner question, but I've noticed that in the official three.js examples, the PointerLockControls.js allows for mouse pointer lock and WASD key navigation. I have successfully locked the mouse pointer, but I am having troubl ...

After minimizing the window, the jQuery slider animation sped up significantly

I am currently using a coda slider on my website, but I have encountered an issue where the content slider plays too fast after the window is minimized. I believe this may be related to the use of SetTimeout, but I have not been able to find a perfect so ...