Search code examples
angularjsangularjs-injector

Pulled out all my hair on an Angular unpr error


So I am getting an angular [$injector:unpr] error. Yes, I know what that normally means...I haven't defined something somewhere, or I am redefining the module over and over, or the like...but for the life of me I'm struggling to see the issue in my code.

I'm sure I'm missing something insanely basic, but after I've stared at code for a couple of hours, I go blind to it.

My HTML File:

<!DOCTYPE html>
<html ng-app="email">
<head>
    <meta charset="UTF-8">
    <title>Authentication</title>
    <link href='https://fonts.googleapis.com/css?family=Roboto:400,100,300,500,700' rel='stylesheet' type='text/css'/>
    <meta content="width=device-width, initial-scale=1.0" name="viewport">
</head>
<body>
    <script src="bower_components/jquery/dist/jquery.min.js"></script>
    <script type="text/javascript" src="node_modules/angular/angular.min.js"></script>
    <div ng-controller="EmailAuthController as auth">
        <h1>Authentication</h1>
        <p>Request: [{{auth.request}}]</p>
        <p>{{auth.response}}</p>
        <p>{{1+2}}</p>
    </div>
    <script type="text/javascript" src="js/controllers/email.js"></script>
</body>
</html>

My email.js file (As you can see, I've commented out some stuff to try to isolate the issue):

/* global angular parseGet */
function parseGet(val) {
    var result = '', // = "Not found",
        tmp = [];
    var items = location.search.substr(1).split('&');
    for (var index = 0; index < items.length; index++) {
        tmp = items[index].split('=');
        if (tmp[0] === val) {
            result = decodeURIComponent(tmp[1]);
        }
    }
    return result;
}

(function () {
    angular
        .module('email', [])
        .controller('EmailAuthController', [ '$scope','authFactory', function ($scope,authFactory) {
            var vm = this,
                req = parseGet('hash') || '';
            vm.request = req;
            // authFactory.validate(req)
            //     .then(function (response) {
            //         vm.response = response.data;
            //     });
        }])
        .factory('authFactory', [ '$rootScope', '$http', 'config', function ($rootScope, $http, config) {
            var validate = function (hash) {
                var url = config.SERVICE_URI + '/auth/email/' + hash;

                return $http.get(url);
            };

            return {
                validate: validate
            };
        }]);


})();

Solution

  • From the code you've given it appears config is not defined in your authFactory injection.

    .factory('authFactory', [ '$rootScope', '$http', 'config', function(a, b, c) {} ]); // config is not defined