n00n
n00n

Reputation: 664

$routeProvider is not defined

I have create a new project, but got a problem which I am not able to fix.

Here's my example:

angular.module('MosysTimes', ['ngRoute']).config($routeProvider, RouteConfiguration);

function RouteConfiguration ($routeProvider) {
    $routeProvider
        .when('/', {
            templateUrl: 'start.html',
            controller: 'WelcomeController'
        })
        .when('/login', {
            templateUrl: 'login.html',
            controller: 'LoginController'
        })
        .otherwise({
            redirectTo: '/'
        });
}

It always says:

$routeProvider is undefined....

Any help will be appreciated ?

Upvotes: 2

Views: 4151

Answers (5)

n00n
n00n

Reputation: 664

thanx to you all, after trying your hints I got it working and a bit of more understanding angular.. thx...

Upvotes: 0

Vinay
Vinay

Reputation: 558

angular.module('yourModule').config(['$routeProvider', function($routeProvider){
$routeProvider
  .when() .....
}]);

Upvotes: 1

Oleksandr
Oleksandr

Reputation: 5668

Did you add ngroute script to you index html? for example:

 <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.25/angular-route.min.js"></script>

and try to use following syntax

angular.module("MosysTimes",['ngRoute']).config(function($routeProvider) {
   $routeProvider
    .when('/', {
        templateUrl: 'start.html',
        controller: 'WelcomeController'
    })
    .when('/login', {
        templateUrl: 'login.html',
        controller: 'LoginController'
    })
    .otherwise({
        redirectTo: '/'
    });
});

Upvotes: 1

Kalu Singh Rao
Kalu Singh Rao

Reputation: 1697

You should declare $routeProvider into function. After that you can use this $routeProvider to access the loading template on your main page.

Upvotes: 0

zeeshan Qurban
zeeshan Qurban

Reputation: 387

You should change your code to this.

angular.module('MosysTimes', ['ngRoute']).config(['$routeProvider',function($routeProvider)
{
$routeProvider
    .when('/', {
        templateUrl: 'start.html',
        controller: 'WelcomeController'
    })
    .when('/login', {
        templateUrl: 'login.html',
        controller: 'LoginController'
    })
    .otherwise({
        redirectTo: '/'
    }); 
}]);       

Upvotes: 1

Related Questions