Oops! The $injector is throwing a Module Error because it can't find the property 'when' in Angular

I have been researching for the past two days to solve this error but still no luck. I am new to angular and have been following this tutorial:

Everything was going smoothly until my grid stopped filling with data. After making some minor code changes, I encountered this error.

In my JavaScript file:

var MyApp = angular.module("Myapp", ["ngResource", "ngRoute"]).
    config([function ($routeProvider) {
        $routeProvider.when('/', {templateUrl: 'list.html', controller: 'ListCtrl' }).
            otherwise({ redirectTo: '/' });
    }]);


MyApp.factory('Myapp', function ($resource) {
    return $resource('/Myapp/:id', { id: '@id' }, { update: { 
        method: 'PUT' } });
});


MyApp.controller('ListCtrl', ['$scope', 'ds72', function ($scope, Myapp) {
    $scope.todos = Myapp.query();
}]);

Could someone please help me understand what I am doing wrong?

PS: These are all the scripts I am using

<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.21/angular.min.js"></script>
        <script src="/Scripts/jquery-1.10.2.js"></script>
        <script src="/Scripts/angular.js"></script>
        <script src="/Scripts/angular-resource.min.js"> </script>
        <script src="/Scripts/angular-route.min.js"></script>

Answer №1

Give this a try

var MyApplication = angular.module("Myapplication", ["ngResource", "ngRoute"]).
    config(['$routeProvider',  function ($routeProvider) {
        $routeProvider.when('/', {templateUrl: 'list.html', controller: 'ListCtrl' }).
            otherwise({ redirectTo: '/' });
    }]);

Remember to include the provider's name in the array declaration for injection

.config(['$routeProvider'/*must be the exact name*/, function(route/*get the $routeProvider value*/) {}])
//equivalent as
.config(function($routeProvider) {})

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

JSON data not displaying correctly in bootstrap table

I've been grappling with this issue for hours now, but I'm struggling to get my bootstrap table populated correctly. Here's the snippet of my HTML: <html> <head> <link rel="stylesheet" href="https://code.jquery.com/ui/1.1 ...

Encountered a deployment issue when trying to deploy an HTML application on Heroku due

After uploading an html application on GitHub, I encountered an error while attempting to deploy it on Heroku: No default language could be detected for this app. HINT: This happens when Heroku is unable to automatically determine the buildpack to use f ...

Error: Unable to access the 'name' property of an undefined value. Despite my efforts, I am unable to determine the root cause of this issue. My technology stack includes mysql for the database, nodejs for the backend,

Can someone help me with a TypeError: Cannot read property 'name' of undefined error I'm encountering while trying to add new users to a MySql database using Node.js and EJS as the view engine? I've been unable to identify the cause of ...

Having trouble with jQuery functioning on mobile devices?

I'm experiencing an issue where this code works perfectly on my desktop, but not on my mobile device. I've tried using different browsers on my mobile, but the code still doesn't function. Any assistance would be greatly appreciated. var li ...

What could be the reason for Jest throwing an error during the testing of the `Colyseus` game?

Currently, I am evaluating the functionality of a game using Jest as both a testing framework and assertion library. Below is my test configuration: const { Server } = require("colyseus") const { ColyseusTestServer, boot } = require("@colyse ...

Is there a particular motive behind the decision for `arguments` to be treated as an object

Today while coding, I came across something puzzling. arguments.concat(someNumber); This line gave me an error for undefined function. Initially, I assumed that arguments was a native object for optimization purposes, but later discovered it's simp ...

Attempting to transfer a JSON object from a frontend Form Input to an Express backend

Apologies for bringing up what may seem like a basic issue, but I've been searching extensively (even through axios' documentation) and haven't been able to pinpoint exactly what I need to resolve this issue. I have created a simple To-Do we ...

Utilize the NPM package manager in the zsh shell on Ubuntu within a Windows 10

After transitioning to the zsh for coding in Python and configuring the environment variables, I am now encountering an issue while trying to start a small JavaScript project. The problem arises when attempting to use npm, as initializing the repo results ...

What is the best way to ensure an observable has been updated before proceeding with additional code execution?

Is an observable the best choice for providing live updates of a variable's value to another class? I have a loop in my service class that looks like this: elements.forEach(element => { doStuff(); this.numberSubject.next(valueFromDoStuff); }) ...

The presence of certain characters is leading to problems in the console

Similar Question: Escaping a String for JavaScript Usage in PHP? The characters in my text are causing errors. When I input special characters such as: !\"$%^&()-=\'.,:;/?#~/\\>< An error saying "Syntax error ...

How can I manually set a date in Angular bootstrap datepicker?

Using the Angularjs Bootstrap datepicker has been a great experience, but I encountered a problem when attempting to select the date using JavaScript. How can I ensure that the selected date in the datepicker matches the date read from a specific object, s ...

Manipulating data with Angular's array object

I am having an issue with posting an object array. I anticipate the post to be in JSON format like this: {"campaign":"ben", "slots":[ { "base_image": "base64 code here" } ] } However, when I attempt to post ...

Verify the correctness of two password fields using jQuery

I need help finding a script that can actively check if the passwords entered in two password fields match while typing. The script should indicate if the passwords do not match without needing to click the Submit button. Below are the two password fields ...

Exploring the depths of JSON using @attributes and @association in the realm of JavaScript and AngularJS

Currently, I am working on a project that involves utilizing an API for data retrieval, updates, and deletions. The API in question is the prestashop API. While I have managed to retrieve data and update certain items successfully, I encountered an issue. ...

The circular pattern includes six circles perfectly arranged within the larger circle

Can someone help me achieve perfect circular buttons using Bootstrap, CSS, and HTML5? I've tried my best but need some assistance to make them responsive as well. Here is the code I've been working on: <div class="col-md-12"> ...

Rails 4 does not properly handle the execution of Ajax responses

Currently, I am incorporating ajax functionality within my Rails application. Within the JavaScript file of my application, the following code snippet is present: $('#request_name').on('focusout', function () { var clientName ...

How can I rearrange the output produced from a form by utilizing arrays?

The following code snippet generates the output: Apple,Orange Sliced,Diced Option1 Option2 Option3 Option4 ,Option1 Option2 Option3 Option4 Desired output: Apple Sliced Option1 Option2 Option3 Option4 Orange Diced Option1 Option2 Option ...

Error encountered in unit testing of angularJs due to undefined service

I have been encountering this error and have tried various solutions found online, such as the example provided at , but none of them seem to be working. *****app.js var app = angular.module('myApp', ['ui.router','ui.bootstrap&a ...

Is there a way to implement a feature that automatically closes the chatbot when the user clicks outside of it?

Here is an example of my HTML code: <div class="chatbot chatbot--closed "> <div class="chatbot__header"> <p><strong>Got a question?</strong> <span class="u-text-highlight">Ask Harry</span></p> < ...

Exploring the power of AngularJS for previewing multiple images

I am trying to enhance my code to allow the selection and display of multiple images on the browser instead of just one at a time. However, I'm encountering some issues with my current implementation. How can I modify my code to achieve the desired ...