Unable to lazily load controllers in Angular using oc.lazyLoad - unable to locate controller

Implementing lazy loading in my Angular project:

This is the relevant app.js code snippet:

var app = angular.module('eva', ['ui.router',
  'controllers', 'oc.lazyLoad']);

app.config(['$stateProvider', '$urlRouterProvider', '$httpProvider', '$locationProvider', '$ocLazyLoadProvider',
  function($stateProvider, $urlRouterProvider, $httpProvider, $locationProvider, $ocLazyLoadProvider) {
    $httpProvider.interceptors.push('AuthInterceptor');

    $urlRouterProvider.otherwise("/");
    $locationProvider.hashPrefix('!');

    $stateProvider.state('challenge', {
      url: '/challenges',
      templateUrl: 'views/Challenges.html',
      controller: 'ChallengeCtrl',
      onEnter: ['$state', 'auth', function($state, auth) {
        if (!auth.isLoggedIn()) {
          $state.go('login');
        }
      }],
      resolve: { // Any property in resolve should return a promise and is executed before the view is loaded
        loadMyCtrl: ['$ocLazyLoad', function($ocLazyLoad) {
          // you can lazy load files for an existing module
          return $ocLazyLoad.load('js/controllers/ChallengeController.js');
        }]
      }

This piece of code defines my controller:

angular.module('eva').controller('ChallengeCtrl', ['$scope', 'auth','$translate', 'challengeFactory', 'userFactory', 'userService',
  function($scope, auth, $translate, challengeFactory, userFactory, userService) {

The challengecontroller.js file is not directly included in the index.html file.

I have included oclazyload just before app.js in the index.html file:

<script type="text/javascript" src="js/lib/oclazyload/dist/ocLazyLoad.js"></script>
        <script type="text/javascript" src="js/app.js"></script>

Upon running the app, I encounter this error:

Error: [ng:areq] http://errors.angularjs.org/1.4.7/ng/areq?p0=ChallengeCtrl&p1=not%20a%20function%2C%20got%20undefined

I have tried various approaches for lazy loading without success. Currently, I am following the example provided on this Example link.

I am facing difficulties with lazy loading implementation and unsure how to proceed. I prefer not to use requirejs in this scenario.

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

Steps to make pop-up iframe function on the same page within a react nextjs application

My vanilla Html app has a pop-up feature that functions perfectly. When the button is clicked, the pop-up opens and everything works as expected. However, I am encountering an issue when trying to implement this same functionality in my React, NextJS app. ...

Bootstrap 5 dual carousel focus

I have implemented a combo carousel that serves as a timeline slider and displays 14 dates. Along with thumbnails, I am also using dates for navigation. To handle the large number of dates, I need to display them in separate rows, but only show one row at ...

How can I position 7 images absolutely within a specific div?

I've been working on a website where users can have their avatars displayed using a JS function that loads 7 different images onto the page. These images correspond to different elements such as skin base, hair, eyes, mouth, shirt, shoes, and pants, a ...

Locating the matching value in the <select> element and showcasing it

I'm trying to create a function where selecting an option from one dropdown menu will display the corresponding value in another column. For instance, if someone chooses "3" from the first dropdown, the value displayed in the third column should be "3 ...

The JQuery pagination event onPageClick is persistently in motion

If I have a div identified as "pagination-demo" with a total number of pages set to 5, this is how I would initialize it: function InitializePagination(totalPage) { opts = { totalPages: totalPage, visiblePages: 5, onPageClick: ...

Check if the page has been loaded using Jquery

Can anyone share a helpful strategy for initiating a function in JavaScript that only begins once the entire page has finished loading? ...

Exploring the Inheritance of Scope Objects in AngularJS

Seeking guidance from an AngularJS expert on understanding AngularJS Scope and Inheritance. I have a scenario where I add a child scope to a parent scope, then try to add a new object to the parent scope using array.push(); However, I am puzzled as to why ...

Break down for me what Json is in a way that a five-year-old could understand

Let me clarify one thing, I may not be a Javascript expert but I'm far from being 5 years old. Json is one concept that's been confusing me lately as I dive into the world of programming. Can someone please explain json to me in a simplified mann ...

A validator module encountered a TypeError

Encountering an issue with the validator when validating data. TypeError: _validator2.default.isNull is not a function After installing validator using npm install --save validator (version [email protected]) The usage of validator in the function ...

Encountered an error while attempting to route to view: TypeError - Unable to access 'childNodes' property of an undefined object

My main HTML contains a view called 'options': <div class="container-fluid" > <div class="row" > <div class="col-sm-3 col-md-2 sidebar"> <ul class="nav nav-sidebar"> ...

Removing an item from a Firebase array: A step-by-step guide

I'm currently facing a challenge with removing a specific object/field within a document in Firebase. While I can delete entire collections or documents, I'm struggling to delete the name and tag fields associated with a particular ID. Is there a ...

Utilizing jQuery to seize events and handle AJAX callbacks

I am attempting to accomplish a simple task: capture any click event and send the URL to a PHP script. When using alert(a); the ajax.php is called every time. However, if I remove it, only once in every 20 clicks will work. I am wondering if this is due t ...

The error encountered at line 8 in the file ui-bootstrap-tpls-0.14.3.min.js is: "Uncaught ReferenceError:

Everything was working perfectly in my application until I decided to install ui-bootstrap-tpls-0.14.3.min.js I added ui.bootstrap as a dependency like this: var app = angular.module("earnfitApp", ['ngRoute','ui.bootstrap']); I made ...

From jQuery to Vanilla JavaScript: Implementing a simple click event listener

I've been attempting to translate the following jQuery code into vanilla JavaScript, however, I can't get it to function properly. jQuery: $(document).ready(function() { $("button").click(function() { var char = "0123456789abcdefghijklmno ...

breaking up various dates into specific formatting using React

I need to convert a series of dates Wed Nov 13 2019 00:00:00 GMT+0000 (UTC),Tue Nov 19 2019 00:00:00 GMT+0000 (UTC),Tue Nov 19 2019 00:00:00 GMT+0000 (UTC) into the format 11/13/2019, 11/19/2019, 11/19/2019 ...

Tips on inserting JS code into React component

I seem to be struggling with integrating my JS code into a React component. I attempted it, but unfortunately made a mess of things. Can anyone provide guidance on how to properly accomplish this? mycomponent.js import React from "react"; import Navbar ...

What is causing my Node JS app to only show the initial JSON object?

Having an issue with my Node application while writing a JSON object and integrating the Twilio API. The console log displays all objects properly, but when written to the document, only the first object is visible. Can anyone help me figure out why this d ...

Clicking a button in Angular JS to refresh a specific ID element

Just diving into AngularJS for my mobile web app development. I have different id divs for each view, as that's how AngularJS operates with one HTML page. My goal is to use specific javascript for each id page, as they need to retrieve JSON data objec ...

Accessing this.href from the ASP.NET code behind using Javascript

I'm trying to pass this.href from my asp.net code behind to JavaScript. When I run the code, the value appears as 'undefined' in the alert message. Can anyone help me with this issue? Page.ClientScript.RegisterStartupScript(this.GetType(), ...

Regular expression that can be used to extract information from a text file by filtering and returning only

When I open a text file, it contains several lines like the examples below. surname australia enter name j.jonhs enter name j.cause enter name f.london enter I am seeking assistance to modify the code snippet below so that it captures the first line m ...