Vladyn
Vladyn

Reputation: 583

AngularJS unknown provider: $routeProviderProvider

I'm struggling with this unknown provider error and just wondering what I'm doing wrong. Have this structure:

in main.js

'use strict';

angular.module('myApp')
  .controller('MainCtrl', ['navService', function (navService) {
    this.awesomeThings = [
    'HTML5 Boilerplate',
    'AngularJS',
    'Karma'
];

  this.active = false;

  navService.getPosition();

}]);

In index html I have ng-controller="MainCtrl" And finally in navService:

angular.module('myApp')
.factory('navService', ['$routeProvider', '$location', function ($routeProvider, $location) {
    function getPosition() {
        /*code here */
    }

    return {
        getPosition: getPosition
    };
}]);

In main app.js

angular
  .module('cavyrApp', [
'ngAnimate',
'ngCookies',
'ngMessages',
'ngResource',
'ngRoute',
'ngSanitize',
'ngTouch'
  ]).config...........

Upvotes: 0

Views: 1045

Answers (2)

Alexander Kravets
Alexander Kravets

Reputation: 4395

$routeProvider is a provider - you can not inject it into factory/service. You can inject it to the config method only - to configure the service it will provide:

module.config(function($routeProvider) {
    // configure the routes here
});

Upvotes: 2

Itsik Mauyhas
Itsik Mauyhas

Reputation: 3984

You should inject your factroy like this:

angular.module('myApp',['ngRoute']); //route inject

and the controller:

angular.module('myApp').controller('MainCtrl',  function(navService) {
});

Upvotes: 0

Related Questions