The module demoApp could not be instantiated because of an error stating that the module demoApp is not accessible

I am struggling to create a basic Single Page Application (SPA) using Angular and ngRoute/ngView. Unfortunately, I can't seem to get it to work properly.

Every time I try, I encounter the error: angular.js:68 Uncaught Error: [$injector:modulerr] Failed to instantiate module demoApp due to: Error: [$injector:nomod] Module 'demoApp' is not available! It seems like there's an issue with either misspelling the module name or forgetting to load it. When registering a module, make sure to specify the dependencies as the second argument.

I've looked at different code examples online and watched numerous YouTube tutorials to compare my code with theirs, but I'm still unable to pinpoint what I'm doing wrong. At first glance, they all appear identical to me.

I apologize in advance if this question has been asked frequently before, but previous solutions haven't helped me in any way.

This HTML file is named "test.html".

<html ng-app="demoApp">
  <head>
        <title>My Angular App</title>

  </head>

  <body>
      <h2>DemoApp Demo</h2>
        <div>
            <a href="#/partial1.html">Partial 1</a>
            <a href="#/partial2.html">Partial 2</a>
            <div ng-view></div>     
        </div>
        <script src = "https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular.js"></script>
        <script src = "https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular-route.js"></script>
        <script src = "demoApp.js" />
  </body>
</html>

The following is the content of "demoApp.js", located in the same directory as test.html

var demoApp = angular.module('demoApp', ['ngRoute']);

demoApp.config(['$routeProvider', function($routeProvider) {
    $routeProvider

        .when('/partial1',
        {
            controller: 'SimpleController',
            templateUrl: 'Partials/partial1.html'
        }).when('/partial2',
        {
            controller: 'SimpleController',
            templateUrl: 'Partials/partial2.html'
        }).otherwise({redirectTo: '/partial1'});
}]);


demoApp.controller('SimpleController', function($scope){
    $scope.customers = [
        {name:'Victor', city:'Norrköping'}, 
        {name:'Mikael', city:'Göteborg'}, 
        {name:'Jocke',  city:'Göteborg'}, 
        {name:'Skåne',  city:'Ystad'}
    ];

    $scope.addCustomer = function(){
        $scope.customers.push(
        {
            name: $scope.newCustomer.name, 
            city: $scope.newCustomer.city
        });
    }
});

I have omitted including Partial1 and Partial2 since they don't seem relevant to the issue, being just simple HTML files without any scripts.

Answer №1

The error lies in this particular line

<script src="..." />

It is not allowed to use self-closing script tags, instead it should be written as

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

To see an example demonstrating the correct method, please visit: http://plnkr.co/edit/Mz1GRSFRxaUN9q6gUONl

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

MERN stack does not have a defined onClick function

I am developing a website for college registration, and I encountered an issue while trying to create a feature that allows students to select a major and view all the associated courses. I made a list of majors with buttons next to them, but whenever I at ...

Is it necessary to integrate the Facebook JavaScript SDK even if I do not plan on utilizing its features?

I have created some simple applications to use as custom tabs on my Facebook page, consisting of hyperlink images. I am not utilizing any of the functionality provided by the Facebook JavaScript SDK in these instances. Do I really need to load the Faceboo ...

ReactJS is giving me an error message: "Uncaught TypeError: Unable to access property 'ownerDocument' since it is null."

Trying to create a bar chart using D3 and render it with React's render method. Below is my index.js file: import React from 'react'; import ReactDOM from 'react-dom'; import './Styles/index.css'; import BarChart from &a ...

Uppercase the initial letter in a term to indicate a standard condition

I'm struggling to override the CSS in material UI. Even though I tried capitalizing both words, it only changes on selected and hover states, Is there a way to change it in the normal state as well? I've tried debugging but can't seem to fin ...

Implementing dynamic class bindings with Vue.js using v-for

I am currently using a v-for loop in Vue.js to create a list of items populated with data from an API. Here is an example of the items array: items: [ { foo: 'something', number: 60 }, { foo: 'anything', ...

Error message: "Module not found" encountered while executing test case

I am a beginner in node and nightwatch and I have followed all the initial instructions from setting up node, npm, selenium standalone, starting the selenium driver. I also downloaded the chrome driver and placed it in the same directory. I created the con ...

Header frame is not valid

I have been working on developing a real-time application using NodeJS as my server and Socket.IO to enable live updates. However, I encountered an error message that reads: WebSocket connection to 'wss://localhost:1234/socket.io/?EIO=3&transpo ...

Converting user input from a string to an object in JavaScript: a comprehensive guide

Is there a way to transform user input string into objects when given an array of strings? ["code:213123", "code:213123", "code:213123"] I am looking to convert this array into an array of objects with the following format: [{code: "213123"},...] ...

Adding Bootstrap modal content to a webpage before it renders is a simple process that involves preloading the

When using Bootstrap modal, is it possible to load a remote URL along with the parent page without needing to click on a button? ...

What is the significance of the space between form.validate and .ng-invalid-email.ng-dirty?

I'm currently working on an AngularJS application and I'm confused about the spacing between "form.validate" and ".ng-invalid-email.ng-dirty" in the stylesheet code below: <style> form.validate .ng-invalid-required.ng-dirty {background ...

The 'userEvent.type' function in React Testing Library is failing to update the input value in a Material UI TextField component that has

I am currently facing an issue with a material UI TextField element that is meant to track the latitude value. The requirement is for the latitude to fall within the range of -90 to 90 degrees. I have implemented a unit test as a validation measure, howeve ...

Issue with setting headers in Express.js when using an exported function

Exploring testing methods with Express using Mocha, Chai, Chai-HTTP plugin, and MongoDB with Mongoose. One particular test is designed to check if MongoDB correctly handles errors when attempting to retrieve a document with a faulty _id value (too short). ...

Is there a way to choose multiple IDs in this code that all share a common word?

I'm attempting to target several duplicate ids such as "img1, img2" in my code, but I haven't had any success. How can I select all the ids that contain the same word without relying on jQuery or any other external libraries? Below is the code s ...

Having trouble with Angular's ng-tags-input? Are you getting the error message "angular is not defined"? Let

I recently created a new Angular project using the following command: ng new "app-name" Now, I'm attempting to incorporate ngTagsInput for a tag input feature. However, every time I try to build and run my app, I encounter an error in my browser con ...

Displaying PDF content in a new browser tab by utilizing JavaScript

Currently, I am utilizing the struts2 framework alongside dojo for the UI. My goal is to display a PDF in a new browser window. The PDF inputstream is obtained from the server through a standard AJAX call using the GET method (not utilizing a Dojo AJAX cal ...

The concept of asynchronicity and callbacks in JavaScript

As a newcomer to the world of JavaScript and Stack Overflow, I have been learning about synchronous, asynchronous, and callbacks through various videos and blogs. However, I still have a lingering doubt. If synchronous code means following a sequential ord ...

What is the best way to include the API body in a GET request?

I'm facing an issue with passing parameters to the body instead of the query in my code. Here's what I have attempted: const fetchData = async () => { let response = await apiCall("URL" + { "companyArr": ["SBI Life Insurance C ...

increasing the size of a picture without resorting to a pop-up window

Struggling to implement a product details tab within a table that features a clickable image. When the image is clicked, it should enlarge but the width doesn't adjust accordingly. I'm using bootstrap 5.3 and can't seem to identify the root ...

Using jQuery in Angular, you can add a div element to hidden elements by appending

So, I have a hidden div that I want to show on button click. And not only do I want to show it, but I also want to append another div to it. The show and hide functionality is working fine, but the appending part seems tricky when dealing with hidden eleme ...

Integrating Livefyre npm with Meteor

Currently, I am in the process of creating a custom package to integrate the livefyre npm module into Meteor after receiving a request from a client. Despite following the instructions provided here, I keep encountering errors that state Errors while scann ...