Search code examples
angularjserror-handlingangularjs-injector

AngularJS[$injector:unpr] Unknown provider


Can somone offer me insight on why I am getting the error in the title based on my code? Not quite sure why.

angular.module("demoApp", ['ngRoute'])

.config(['$routeProvider', '$locationProvider',
    function ($routeProvider, $locationProvider) {
        $routeProvider.
            when('someURL', {
                templateUrl: 'someTemplate.html',
                controller: 'CreateGrids'
            });
        $locationProvider.html5Mode(true);
    }
])
.factory("servers", function () {
    var servers = {};
    ...
    return servers;
})
.factory("setup", function () {
    var setup = {};
    ...
    return setup;
})
.factory("gridservice", ['$http', function ($http) {
    var gridservice = {};
    ...
    return gridservice;
}])
.controller('MainCtrl', ['$route', '$routeParams', '$location',
    function ($route, $routeParams, $location) {
        this.$route = $route;
        this.$location = $location;
        this.$routeParams = $routeParams;
        console.log(this.$routeParams);
    }
])
.controller("CreateGrids", ['$routeParams', '$scope', '$http', 'setup', 'server', 'gridservice', function ($routeParams, $scope, $http, setup, servers, gridservice) {
    this.name = 'CreateGrids';
    this.params = $routeParams;
    console.log($routeParams);
    ...
}])
.controller("ServerRepeat", ['$scope', 'servers', 'setup', function ($scope, servers, setup) {
    ...
    }
}]);

I've gone over the code multiple times to try and find what's causing the error but to no avail. Is it because I'm calling things between controllers and factories?

EDIT: This is the error

Error: [$injector:unpr] http://errors.angularjs.org/1.3.0-beta.17/$injector/unpr?p0=serverProvider%20%3C-%20server
at Error (native)
at https://ajax.googleapis.com/ajax/libs/angularjs/1.3.0-beta.17/angular.min.js:6:457
at https://ajax.googleapis.com/ajax/libs/angularjs/1.3.0-beta.17/angular.min.js:37:55
at Object.d [as get] (https://ajax.googleapis.com/ajax/libs/angularjs/1.3.0-beta.17/angular.min.js:35:74)
at https://ajax.googleapis.com/ajax/libs/angularjs/1.3.0-beta.17/angular.min.js:37:129
at d (https://ajax.googleapis.com/ajax/libs/angularjs/1.3.0-beta.17/angular.min.js:35:74)
at e (https://ajax.googleapis.com/ajax/libs/angularjs/1.3.0-beta.17/angular.min.js:35:335)
at Object.instantiate (https://ajax.googleapis.com/ajax/libs/angularjs/1.3.0-beta.17/angular.min.js:35:494)
at $get (https://ajax.googleapis.com/ajax/libs/angularjs/1.3.0-beta.17/angular.min.js:69:169)
at https://ajax.googleapis.com/ajax/libs/angularjs/1.3.0-beta.17/angular.min.js:54:454

Solution

  • Based on the error given back , change

      .controller("CreateGrids", ['$routeParams', '$scope', '$http', 'setup', 'server', 'gridservice', function ($routeParams, $scope, $http, setup, servers, gridservice) {
    

    to

     .controller("CreateGrids", ['$routeParams', '$scope', '$http', 'setup', 'servers', 'gridservice', function ($routeParams, $scope, $http, setup, servers, gridservice) {
    

    you typo'd servers as server.

    For future knowledge - when angular gives you that error stack, click the top hyper link and it will bring you to a page telling you a lot more about the error. This link for reference - here