Encountering the AngularJS .Net Core routing $injector:modulerr error

I'm currently learning about .Net Core and AngularJS by following tutorials. However, I've encountered an error while attempting to implement client routing in the newest version of .Net Core with default configuration. The AngularJS error I received was: $injector:modulerr Module Error

To troubleshoot this issue, I created a separate project to focus solely on testing routing. Here is some sample code:

(function () {
'use strict';

angular.module('routeApp', ['ngRoute']).config(config);

function config($routeProvider, $locationProvider) {

    $routeProvider
        .when('/', {
            templateUrl: '/Views/home.html',
            controller: 'HomeController'
        })
        .when('/about', {
            templateUrl: '/Views/about.html',
            controller: 'AboutController'
        })
        .otherwise({
            redirectTo: '/'
        });

    $locationProvider.html5Mode(true);
};
})();

Here are the controllers used:

(function () {
'use strict';

angular
    .module('routeApp')
    .controller('HomeController', HomeController)
    .controller('AboutController', AboutController)
    .controller('ErrorController', ErrorController);

HomeController.$inject = ['$scope']; 

function HomeController($scope) {
    $scope.message = "Welcome homepage";
}

AboutController.$inject = ['$scope'];

function AboutController($scope) {
    $scope.message = "This is about page";
}

ErrorController.$inject = ['$scope'];

function ErrorController($scope) {
    $scope.message = "Error 404!";
}

})();

And here is the index.html file for reference:

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title>AngularJS Routing App</title>

    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular.min.js"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular-route.js"></script>

    <script src="app.js"></script>

</head>
<body ng-app="routeApp">

    <a href="/">Home</a>
    <a href="/about">About</a>
    <div>
        <ng-view></ng-view>
    </div>

</body>
</html>

Can anyone help me identify what's causing this error? Do I need any specific server configurations?

PS. I'm using Visual Studio 2015 with Update 3.

PS2. Browser stack trace:

Uncaught Error: [$injector:modulerr] Failed to instantiate module routeApp due to:
Error: [$injector:unpr] Unknown provider: a
http://errors.angularjs.org/1.5.6/$injector/unpr?p0=a
...

PS3. Minified app.js

!function(){"use strict";function a(a,b){a.when("/",{templateUrl:"/Views/home.html",controller:"HomeController"}).when("/about",{templateUrl:"/Views/about.html",controller:"AboutController"}).otherwise({redirectTo:"/"}),b.html5Mode(!0)}angular.module("routeApp",["ngRoute"]).config(a)}(),function(){"use strict";function a(a){a.message="Welcome homepage"}function b(a){a.message="This is about page"}function c(a){a.message="Error 404!"}angular.module("routeApp").controller("HomeController",a).controller("AboutController",b).controller("ErrorController",c),a.$inject=["$scope"],b.$inject=["$scope"],c.$inject=["$scope"]}();

Answer №1

Ensure that the application is being executed on a server.

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

Troubles encountered when attempting to use Axios to call a third-party API in a React JS application

Challenge Description: I set out to create a dropdown menu of post-offices based on the user-entered pincode. To achieve this, I utilized an API and Axios for the backend request. While I successfully populate the dropdown with the necessary data, the is ...

Running JavaScript function from AJAX response containing both HTML and JavaScript code

For my first time using AJAX to prevent page refresh upon form submission, everything works flawlessly. The data is received in HTML form and placed into the designated div. However, I am encountering an issue with one of the JavaScript functions responsib ...

Create a query string using JavaScript and combine multiple parameters into a single param

I am facing a challenge where I need to construct a query string in JavaScript and nest various parameters within one of the parameters. In PHP, I can achieve this using the http_build_query function. However, when attempting to do the same in JavaScript, ...

Switch image on click (toggle between pause and play buttons)

Having some difficulty setting up a 3D audio player in A-Frame where the pause and play button images need to change depending on whether the audio is playing or not. Interested in seeing my code in action? Check it out here. ...

Utilizing ajax for fetching a data table

I am new to using ajax and have successfully retrieved data from a table. However, I am now trying to pull in an entire data grid but not sure how to achieve this. In my index.php file, I have the following code: <html> <head><title>Aj ...

Troubleshooting a pair of .factory errors in AngularJS and Ionic

I am facing an issue with two .factory functions, where the second one throws an error. It seems like there is a restriction on having multiple .factory functions. Any assistance would be greatly appreciated. Thank you .factory('RawData', func ...

The function `jQuery .html('<img>')` is not functional in Firefox and Opera browsers

This particular code snippet jq("#description" + tourId).html('<b>Opis: </b> '+ data); has been tested and functions correctly in Internet Explorer, Firefox, and Opera. However, when it comes to this specific piece of code jq("#i ...

An issue arose during the installation of nodemon and jest, about errors with versions and a pes

Currently, I am facing an issue while trying to set up jest and nodemon for my nodejs project. My development environment includes vscode, npm version 6.13.7, and node version 13.8.0. Whenever I try to install nodemon via the command line, the console disp ...

My ability to click() a button is working fine, but I am unable to view the innerHTML/length. What could be the issue? (NodeJS

Initially, my goal is to verify the existence of the modal and then proceed by clicking "continue". However, I am facing an issue where I can click continue without successfully determining if the modal exists in the first place. This occurs because when I ...

Set the display property of all child elements within the DIV to none

CSS <div class="container"> <span></span> <input type="text"> </div> JavaScript function hideElements(){ let container = document.querySelector(".container"); let elements = ...

The storage of HTML5 data is not being saved locally

<html> <head> <title></title> <style type="text/css"> body { font-family: tahoma; } h2 { font-weight: bold; border-bottom: 2px solid gray; margin-bottom: 10px; } #dat ...

Need to know how to retrieve the li element in a ul that does not have an index of 2? I am aware of how to obtain the index greater than or less

I'm looking to hide all the li elements except for the one with a specific index. I've written some code to achieve this, but I'm wondering if there's a simpler way using jQuery. While jQuery provides methods like eq, gt, and lt, there ...

Generating an interactive table using JSON with Angular 5

Can a dynamic table with dynamic columns be created based on a JSON object using Angular 5? If yes, how? The API response includes the following JSON: { "ResponseStatus": true, "ResponseData": [ { "Parent": "Company 1", ...

The getServerSideProps function in Next.js is only executed once, meaning it won't retrieve fresh data when accessed via next/router

I'm working on a Next.js application with Server-Side Rendering (SSR) where I have an async function called getServerSideProps that is exported like this: export const getServerSideProps = getGenericServerSideProps([""]); The getGenericServerSideProp ...

The error message displays "window.addEventListener is not a function", indicating that

Recently, I've been dealing with this code snippet: $(document).ready(function(){ $(window).load(function() { window.addEventListener("hashchange", function() { scrollBy(0, -50);}); var shiftWindow = function() { scrollBy(0, - ...

Is there a way to clear the input value in the otp field?

Here is the codepen link I mentioned earlier: https://codepen.io/santoshch/pen/LYxOoWO <button @click="resetNow(id)"></button> resetNow(id){ this.$refs[`input-${id}`].input.value = ""; //In some cases, you may need to u ...

Extracting raw data from the dojo.xhrGet request

When working with a JSP and servlet, I encountered an issue. In the JSP, I make an ajax call to the servlet which in turn calls a REST API to fetch JSON data. Using json.serialize(true);, I format the JSON data in the servlet before sending it to the front ...

The issue with Nuxt's vue-Router page transitions not functioning properly is due to the presence of a request

Encountering an issue with the combination of nuxt/vue-router page-transitions and the JavaScript method rerequestAnimationFrame. Currently, I am animating a container of items using rerequestAnimationFrame along with the transform: translate CSS property. ...

Error: Unable to use map function on users .. cannot perform mapping on functions

Initially, the map function in my code was working fine. However, suddenly an error started appearing when I included the users.map line. Surprisingly, if I comment out that line, the code works perfectly again. Even more strangely, if I uncomment it, ev ...

Implementing relative path 'fetch' in NextJs App Router

When attempting to retrieve data using fetch("/api/status"), the URL is only detected when utilizing the absolute path: fetch("http://localhost:3000/api/status"). This is happening without storing the path in a variable. ...