Marc Thomas
Marc Thomas

Reputation: 393

AngularJS Routing Configuration not called

I am running through a course at the moment on AngularJS and it has just introduced the concept of routing.

My problem is the app.config function is setup in app.js however, the function doesn't seem to ever be called and therefore the routes are not setup.

The common problem is the ngRoute not being declared however, it is. I'm not sure if there is a problem with the versions of Angular that I'm using but these were taken from the online course.

I have a public plnkr for anyone to view and have a look at http://plnkr.co/edit/L2FG4M?p=preview

(function() {
  var app = angular.module("githubViewer", ["ngRoute"]);

  app.config(function($routeProvider) {
    // If we navigate to /main then the page used will be main.html and the controller
    // MainController, if however something else is provided then we will
    // redirect to /main as well
    $routeProvider.when("/main", {
      templateUrl: "main.html",
      controller: "MainController"
    })
    .otherwise({
      redirectTo: "/main"
    });
  });
}());

Any help is appreciated, I've exhausted my options now.

Thanks Marc

Upvotes: 0

Views: 190

Answers (1)

eladcon
eladcon

Reputation: 5825

In your MainController.js file, you defined a new module with same name as in app.js:

angular.module("githubViewer", []);

What you want to do is retrieve the already defined module. You can acheive that by removing the []:

angular.module("githubViewer");

Look here at the "Creation versus Retrieval" section.

Upvotes: 3

Related Questions