SUMEET DEWANGAN
SUMEET DEWANGAN

Reputation: 161

AngularJs routeProvider error

I am facing problem with routeProvider, don't know why its not working. The problem is with the config function .Here's the code

var mainApp = angular.module('mainApp', []);

mainApp.config(['$routeProvider' ,function($routeProvider) {
   $routeProvider.
    when('/', {
        templateUrl: 'index.html',
        controller: 'indexController'
    }).
    when('/first', {
        templateUrl: 'first.html',
        controller: 'firstCtrl'
    }).
    when('/second', {
        templateUrl: 'second.html',
        controller: 'secondCtrl'
    }).
    otherwise({
        redirectTo: 'index.html'
    });
}])

mainApp.controller('indexController', [function() {
    this.outputString = "String from the index controller";
}]);

mainApp.controller('firstCtrl', ['$scope', function($scope) {
    $scope.outputString = "String from the first controller";
}]);

mainApp.controller('secondCtrl',['$scope', function($scope) {
    $scope.outputString = "String from first controller";
}]);

Error Info

Upvotes: 3

Views: 339

Answers (1)

adolfosrs
adolfosrs

Reputation: 9389

Your application is missing the angular-route module.

Make sure you add it with:

<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.0/angular-route.min.js"></script>

or, if you are using bower, add "angular-route": "^1.4.0" to bower.json and run bower install.

Last, make sure you are injecting ngRoute into you application

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

Here is a working jsFiddle.

Upvotes: 1

Related Questions