Search code examples
angularjsroutesresolve

Angularjs: Unknown Provider


I'm trying to resolve a promise before instantiate a route in angularjs but I'm getting Unknown provider error and I don't know why, I have basically the exact same code in another app.

The error is: Error: [$injector:unpr] Unknown provider: userProvider <- user

Here is my config:

$routeProvider.when('/', {
        redirectTo: '/main'
    }).when('/main', {
        controller: 'MainController',
        templateUrl: 'app/wiki/partials/MainView.html',
        resolve: {
            user: function($http) {
                return routeController.accessLevel($http, 0);
            }
        }
    })

var routeController = app.controller('routeController', ['$scope', function($scope) {

}]);

routeController.accessLevel = function($http, access) {    

    return $http({
        method: 'POST',
        url: "/users/auth/" + access,
        headers: {'Content-Type': 'application/x-www-form-urlencoded'}
    }).success(function(data, status, headers) {
        return data;
    }).error(function(data, status, headers) {
        if(status == 401) {
            window.location.replace('/');
        }
    });


};

angular.module('WikiApp.Controllers.MainController', [])
    .controller('MainController', ['$scope', '$location', '$anchorScroll','user', function ($scope, $location, $anchorScroll, user) {}])

Solution

  • This is just my guess, you might also have an ng-controller="MainController" set in the template MainView.html.