Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AngularJS routeprovider injection error

I'm learning AngularJS, and I'm now trying the $routeProvider, but I can't get it to work.

index.html:

<!DOCTYPE html>

<html ng-app="App">
    <head>
        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.8/angular.min.js"></script>
        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.8/angular-route.min.js"></script>
        <script type="text/javascript" src="scripts/controllers.js"></script>
    </head>
    <body>
        <div ng-view></div>
    </body>
</html>

view.html:

<p>Hello World!</p>

controllers.js:

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

app.config(
    function($routeProvider){
        $routeProvider.when("/something",{
            templateUrl: "view.html",
            controller: "MyController"
        })
        .otherwhise({
            redirectTo: "/"
        });
    }
);

function MyController($scope){

}

Whenever I run this, I get an error message that says

Uncaught Error: [$injector:modulerr]

How can I solve this?

like image 215
Dirk Avatar asked Dec 04 '22 07:12

Dirk


1 Answers

Change .otherwhise to .otherwise.

A good practice when you run into these issues is to try the un-minified version of Angular.

The un-minified error is much more helpful:

Uncaught Error: [$injector:modulerr] Failed to instantiate module App due to: TypeError: Object # has no method 'otherwhise'

like image 55
KayakDave Avatar answered Dec 30 '22 00:12

KayakDave