Troubleshooting: AngularJS ngRoute Issue - Uncaught Error: [$injector:modulerr]

I'm currently trying to diagnose the reason behind this error message that keeps popping up:

Uncaught Error: [$injector:modulerr]


Here's the code snippet from my index.html file:

<!DOCTYPE html>
<html ng-app="MainApp">
<head>
<meta charset="utf-8">
    <link rel='stylesheet' type='text/css' href='core/sty.css'>
    <script src="core/CS/ang/angular.min.js"></script>
    <script src="core/CS/ang/angular-resource.min.js"></script>
    <script src="core/CS/ang/angular-route.min.js"></script>
</head>
    <body>
    <div id="header-cont">
        <div id="header">
            <ul style="list-style:none;">
                <li style="display:inline;float:left;"><font style="font-size:38px;top:-5px;left:-1px;position:fixed;">title</font></li>
                <li class="menu">News</li>
                <li class="menu"><ul class="sub-menu">
                    <a href="/admin/login"><li class="SMoption">1 First login</li></a>
                    <a href="/admin/register"><li class="SMoption">2 Duble register</li></a>
                      </ul>account</li>
            </ul>
        </div>
    </div>
  <ng-view></ng-view>
    <script src="core/CS/mainscript.js"></script>
    <script src="core/CS/config.js"></script>
    <script src="core/CS/controllers.js"></script>
    <script src="core/CS/modules.js"></script>
</body>
</html>



Let's take a look at mainscript.js:

'use strict';

var appv = angular.module("MainApp", ['ngRoute','ngResource']);


And now, config.js:

'use strict';

appv.config(function($routeProvider) {

  $routeProvider.
      when('/', {
        //controller: 'HomeController',
        templateUrl: 'views/home.html'
      }).
      when('/page/:pgId', {
        //controller: 'PageController',
        templateUrl: 'views/page.html'
      }).
      when('/article/:pgId/:artId', {
        //controller: 'ArticleController',
        templateUrl: 'views/article.html'
      }).
      when('/admin/:adCode', {
        //controller: 'AdminController',
        templateUrl: 'views/admin.html'
      }).
  otherwise({templateUrl: 'views/home.html'});
    $locationProvider.html5Mode(true);
});




It seems like everything is set up correctly with the inclusion of ng-route.js and ngRoute module, but for some reason it's not functioning as expected...

Answer №1

To activate html5 mode, simply include

$locationProvider.html5Mode(true);
in your code. However, make sure you have injected the $locationProvider provider into the config function for this to work correctly :)

appv.config(function($routeProvider, $locationProvider ) {
.........

Answer №2

To ensure proper functionality, make sure to add $locationProvider as a mandatory dependency in your config function, as shown below:

'use strict';

appv.config(function($routeProvider, $locationProvider) {

  $locationProvider.html5Mode(true);

  $routeProvider.
      when('/', {
        //controller: 'HomeController',
        templateUrl: 'views/home.html'
      }).
      when('/page/:pgId', {
        //controller: 'PageController',
        templateUrl: 'views/page.html'
      }).
      when('/article/:pgId/:artId', {
        //controller: 'ArticleController',
        templateUrl: 'views/article.html'
      }).
      when('/admin/:adCode', {
        //controller: 'AdminController',
        templateUrl: 'views/admin.html'
      }).
      otherwise({templateUrl: 'views/home.html'});
});

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

Implement generics within the `setState` function in a React.js and TypeScript application to ensure that it returns a string value

I'm facing an issue with setting the state in the onChange event by specifying the type of the setState hook. Here is my current setState declaration: const [payer, setPayer] = useState<Number>(0); And this is the radio setter function I am usi ...

Tips on submitting JSON data to a server

I need the data to be structured like this {"email":"<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="7f0c3f18121e1613511c1012">[email protected]</a>","password":"1"} but it is currently appearing like this { & ...

Definition of Stencil Component Method

I'm encountering an issue while developing a stencil.js web component. The error I'm facing is: (index):28 Uncaught TypeError: comp.hideDataPanel is not a function at HTMLDocument. ((index):28) My goal is to integrate my stencil component i ...

Troubleshooting a JavaScript function's ineffectiveness when triggered by clicking an

What is causing the function to not work properly when I click on the "Rate me" button? function increaseValue(){ var rate = parseInt($("#rateme").value, 10); rate = isNaN(rate) ? 0 : rate; rate++; $("#rateme").value = rate; } <scr ...

Combine rows with the same value in the first column of an HTML table

My HTML table has dynamic content, and I need to merge rows in the first column only if their values are identical. You can see an image of the table here. Specifically, if the values in the first column match, those rows should be merged together while le ...

AngularJS version 1.0.7 introduces a new feature called ng-switch

My web app is built using AngularJS 1.0.7 and includes this code snippet: <div ng-switch="locationService.getLangKey() == 'en'"> <a ng-switch-when="true" class="brand" href="/" ><img src="img/logo.png" style="heigh ...

Prevent further execution upon callback in an AJAX request by stopping the click event function

When the function myClick() is called within itself instead of myLoad() on the first click, it leads to double execution of myClick() on the second click. => This results in two consecutive executions of the click event for #myBtn with just one click. ...

Leveraging ajax data to enhance visual representation in graphs

Having trouble fetching data from a database to display it in a graph.js graph. I've attempted setting a timeout for the async callback from Ajax, but nothing seems to be working. Any suggestions on how to make this work would be greatly appreciated! ...

Ensure password confirmation is correct

Currently, I'm utilizing Yup for form validation. You can check it out here: https://www.npmjs.com/package/yup. Additionally, I came across this package called yup-password which seemed helpful for validating my Formik forms. Here's the link to i ...

Struggling to display filtered content in React using State

As a newcomer to React, I am working on a todo list that shows both current and completed tasks using LocalStorage. Each task has a boolean property called "active" which is toggled when a user clicks on the task checkbox. I have a filter in place to separ ...

encountering validation error during transmission of data through POST request

Creating a Mongoose Model const mongoose=require('mongoose'); const validator=require('validator'); const employeeSchema=new mongoose.Schema({ name:{ type:String, required:true, trim:true }, email ...

Guide to using Vue.js and Vue Router to create a sub menu for the children of the current route

I am currently working on customizing the navigation for my Vue application. My goal is to create a main menu at the top that displays all the root level routes, and a side menu that appears when navigating through child routes. Here is an example of what ...

Error encountered: "XPathEvaluator is not defined" when using IEDriverServer and Internet Explorer with Selenium and Java in Microsoft Dynamics CRM

As part of my testing process for a CRM application with Selenium Java, I encountered an issue with a button that opens a new window. When executing the test, a Script Log Error appears in the new window stating, ReferenceError: 'XPathEvaluator&apo ...

Merging HTML, CSS, and JavaScript in a single file to Generate a Bell Curve with the help of Google Charts API

I'm looking to streamline my code by combining HTML, CSS, and JS into a single HTML script for the existing "Bell Curve Using Google Charts API" project. Check out the project here I've tried putting the CSS in style tags and the JS in script t ...

Challenges encountered with the "load" event handler when creating a Firefox Extension

I am currently troubleshooting a user interaction issue with my Firefox extension. The tasks that my extension needs to complete include: Checking certain structures on the currently viewed browser tab Making backend server calls Opening dialogs Redirect ...

Implement the color codes specified in the AngularJS file into the SASS file

Once the user logs in, I retrieve a color code that is stored in localstorage and use it throughout the application. However, the challenge lies in replacing this color code in the SASS file. $Primary-color:#491e6a; $Secondary-color:#e5673a; $button-color ...

Having issues with the JavaScript controller when using ng-include in the code

Although I have successfully loaded the controller's JavaScript file, I am hesitant to load all controllers on the main page as they have nothing to do with each other. Here is an example of the main page structure: <html lang="en" ng-app="FirstP ...

Seamlessly transition between various states within a React component for a fluid user experience

I'm currently working on a simple component structured like this: var component = React.createClass({ render: function(){ if (this.props.isCollapsed){ return this.renderCollapsed(); } return this.renderActive() }, ren ...

Performing a second Ajax request using information obtained from the initial Ajax call

Currently, I am working on developing an Angular page that interacts with my Nodejs server. However, I have encountered a hurdle in the process. My task involves making multiple Ajax requests, and these requests are interdependent as each subsequent reque ...

Prevent the date each month in asp.net

Is there a way to block Sundays for all months and years in a text box with the Text mode set to Date? <asp:TextBox ID="txtfromdate" runat="server" Enabled="True" OnTextChanged="From_TextChanged" TextMode="Date" ></asp:TextBox> ...