Setting up 'ngProgress' as a loader in my project using the 'ngbp boilerplate' is straightforward and easily customizable

Currently, I am utilizing the 'ngbp' angular boilerplate from GitHub to develop my project. My goal is to implement ngProgress for displaying a loader when navigating between sections.

I have successfully installed ngProgress via bower and ensured that the necessary CSS and JS files are in place.

In my app.js file, the configuration looks like this:

(function(app) {

    app.config(['$stateProvider', '$urlRouterProvider', function ($stateProvider, $urlRouterProvider) {
        $urlRouterProvider.otherwise('/');
    }]);

    app.run(function () {});

    app.controller('AppController', ['$scope', function ($scope) {
    }]);

}(angular.module("grinFood", [
    'grinFood.home',
    'grinFood.about',
    'grinFood.menu',
    'grinFood.catering',
    'grinFood.takeithome',
    'grinFood.contact',
    'templates-app',
    'templates-common',
    'ui.router.state',
    'ui.router',
    'ngProgress',
])));

For instance, the catering.js file contains the following code:

(function(app) {

    app.config(['$stateProvider', function ($stateProvider) {
        $stateProvider.state('catering', {
            url: '/catering',
            views: {
                "main": {
                    controller: 'CateringController',
                    templateUrl: 'catering/catering.tpl.html'
                }
            },
            data:{ pageTitle: 'Catering' }
        });
    }]);

    app.controller('CateringController', ['$scope', function ($scope, ngProgress) {

        var init = function() {
            // A definitive place to put everything that needs to run when the controller starts. Avoid
            //  writing any code outside of this function that executes immediately.
            ngProgress.start();
        };

        init();
    }]);

}(angular.module("grinFood.catering", [
    'ui.router'
])));

However, I encounter an error stating

TypeError: Cannot read property 'start' of undefined
. I also attempted to include ngProgress in the controller within app.js, but without success.

The error can be observed here:

Any assistance or guidance on resolving this issue would be highly appreciated. Thank you.

Answer №1

Initially, it seems that ngbp is outdated. You might want to consider checking out . Additionally, I find it puzzling why you are enclosing app within a function. Unless there is a conflict with another library, this step appears unnecessary.

Do you employ minifiers? If so, make sure to use one that recognizes the AngularJS dependency framework. It's crucial to specify your dependencies accurately.

['$scope', function ($scope, ngProgress)

you can modify it to

function ($scope, ngProgress) 

or

['$scope', 'ngProgress', function ($scope, ngProgress) 

Answer №2

The way you are injecting ngProgress into the controller is incorrect.

Instead of doing this:

app.controller('CateringController', ['$scope', function ($scope, ngProgress) {

You should be doing this:

app.controller('CateringController', ['$scope', 'ngProgress', function ($scope, ngProgress) {

Just a reminder, I switched to using ng-annotate some time ago, and it's a great tool for avoiding these kinds of errors. Personally, I prefer using ng-annotate-rails. These tools can help prevent mistakes like this in the future and also improve the quality of your code. I highly recommend giving them a try!

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

How to make an HTTPS REST API request in Node.js with JSON body payload

Currently, I am attempting to make a secure HTTPS REST request in Node.js by utilizing the following code: var querystring = require('querystring'); var https = require('https'); var postData = { 'Value1' : 'abc1&ap ...

What are alternative methods for sharing data between sibling components in Angular other than $scope?

I am currently developing a component with 3 child components structured like this: <header-component> <side-component> <main-component> The main component displays a list of heroes. The header component includes two buttons that are ...

Error: react-testing-library throwing validateDOMNesting warning

Warning: validateDOMNesting(...): <tbody> cannot appear as a child of <div>. in tbody (created by TableBody) in TableBody (created by TableBody) in TableBody Inquiry: Is there a way to render the TableBody component within a table ...

Discord.js Error: Unable to access undefined properties for 'username'

victim is a variable containing the user's ID input. Despite confirming it as a valid user ID on the server, I encounter the error 'cannot read properties of undefined' This is my first time using client.users.cache.get(victim).username in ...

How can we display a different navbar based on whether the user is logged in or not?

Can anyone share the most effective methods for displaying a different navbar based on whether or not a user is logged in? I have considered a few approaches: One option might involve creating two separate navbars in the HTML file and using CSS to tog ...

Traverse a deeply nested JSON array within an Angular controller to extract distinct values

I am currently facing a challenge where I need to iterate through a nested JSON array structured like this: [ { "title": "EPAM", "technologies": [ "PHP", ".net", "Java", "Mobile", "Objective-C", "P ...

Unable to choose radio button again

Check out this fun web quiz I created! I'm having some trouble with the back button functionality. Whenever a user clicks back, I want to restore their previous choice but for some reason it's not working as expected. Take a look at my go_back ...

"Exploring the depths of sub directories in Node.js: A guide to printing

Once again, I find myself stuck with node.js and in need of your assistance. I am attempting to write a script for the command line interface that will search for all subdirectories under the current directory (process.cwd), and only print out those that ...

The transition between backgrounds is malfunctioning

I want to create a smooth transition effect for changing the background of an element within a setInterval function. Currently, the background changes immediately, but I would like it to transition over a period of time. var act = true; setInterval(func ...

ReactJS requires HTTP server to transpile babel code before running

I am a beginner when it comes to working with reactjs and I am currently in the process of setting up babel to execute babel code without having to serve HTTP files. Following the instructions on the Package Manager, I have successfully installed it along ...

Building a node.is script to validate email addresses

This code snippet is for validating email addresses. I have successfully implemented example 5, where the email length must be over 5 characters to avoid errors and prompt users to re-enter their email address. However, I am unsure how to handle examples ...

Encountering a problem with PDF view in Next.js while using html2canvas and jsp

Currently, I am using html2canvas and jspdf with Next.js to generate a PDF. However, the generated PDF does not display correctly. The h1 tag appears similar to the p tag, which is not the desired outcome. I need assistance in fixing this issue. My goal is ...

Develop a personalized mapping API with a unique image integration for website navigation

Currently, I am in the process of developing a website for my university that will allow users to easily locate all available free food options on campus. My goal is to create a platform where food providers can register their events, have them saved in a ...

There seems to be an issue with Vue JS slots[name$1].every function as it is

I attempted to implement a custom isEmpty function for the Object prototype as follows: Object.prototype.isEmpty = function() { for (var key in this) { if (this.hasOwnProperty(key)) { return false } } return true } However, when tryin ...

Checking the conditions and return statements within Jest testing framework

I recently started diving into Jest and am looking for alternative methods to test this function regarding the If case and return statement using Jest. Here is the function I need help testing: const extractInfo = (description: string) => { cons ...

Error: Unable to define $scope function in Angular and Jasmine integration

I am currently working with a controller var videoApp = angular.module('videoApp', ['videoAppFilters', 'ui.unique', 'angularUtils.directives.dirPagination']); videoApp.controller('VideoCtrl', function ($sc ...

Press the button to switch between displaying one component and hiding another component within reactjs

I am working on a project with two distinct buttons: one for grid view and another for list view. <button onClick={() => setClassName('jsGridView')} title="Grid View" > <IoGrid className="active" s ...

Monitoring the loading progress of multiple files using Three JS

Just starting out with Three JS and I'm on a mission to create a loading screen that displays the progress of assets being loaded for a scene. I have a total of 7 different types of assets, including: 4 GLB files 2 Texture files And 1 Obj file Acco ...

Experiencing difficulties replicating two auto-scrolling divs

I have implemented a script to automatically slide two different divs. Here is the code I am using: The HTML: <div id="gallery"> <div id="slider" style="width: 6000px; left: -500px;"> <div><aside class="widget widget_testimoni ...

Manipulate Nested Objects using an Array of Keys

Currently, I am developing a recursive form using React and MUI that is based on a nested object. Throughout this process, it is crucial for me to keep track of the previous keys as I traverse through the recursion. As users interact with the form and mak ...