user1675891
user1675891

Reputation:

The $routeProvider in Angular can't be found in undefined

I'm following a guide on how to include AngularJS in a MVC project and I got to the point where I'm connecting my controllers (the section's name is Routing).

It seems not to work and when I open the console, I see the following error message.

TypeError: Cannot read property '$routeProvider' of undefined

I've checked all the files in the solution for that string and the only usage of it is in the file where I registered my module. It looks like this.

var CoolApp = angular.module('CoolApp', ["ngRoute"]);
CoolApp.controller('CoolController', CoolController);

var configFunction = function ($routeProvider) {
  $routeProvider
    .when("/one", { templateUrl: "angularRoute/first" })
    .when("/two", { templateUrl: "angularRoute/second" })
    .when("/thr", { templateUrl: "angularRoute/third" });
}

configFunction.$inject["$routeProvider"];
CoolApp.config(configFunction);

I have MVC controller class named AngularRouteController and as far I can see, the only place where I'm "dotting" the $routeProvider is in when statements. Commenting them out doesn't resolve my issue, though. Instead, the line that seems to be the cause of the error is this one.

configFunction.$inject["$routeProvider"];

Due to my ignorance with Angular, I can't see why. As a consequence, I have no idea how to solve the problem. Any suggestions would be welcome. I've googled the issue but that didn't give me anything useful (as far I could judge).

The closest hits I've got was this and this one and they didn't make me any wiser. Not even sure if those are relevant to my problem.

I've made sure that I reference the routing package of Angular separately as suggested in this answer. Should I skip ngRoute and go for ui.router? Not sure what that changes for the guide...

Upvotes: 0

Views: 376

Answers (1)

Peter Keuter
Peter Keuter

Reputation: 788

It looks like you have to change that line to:

configFunction.$inject = [
    "$routeProvider"
];

Upvotes: 1

Related Questions