在Angular unpr错误

时间:2016-06-07 15:35:05

标签: angularjs angularjs-injector

所以我得到一个有角度的[$ injector:unpr]错误。是的,我知道这通常意味着什么......我还没有在某个地方定义某些东西,或者我一遍又一遍地重新定义模块......但是对于我的生活,我一直在努力请参阅我的代码中的问题。

我确定我错过了一些非常基本的东西,但是在我盯着代码几个小时之后,我对它视而不见。

我的HTML文件:

<!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>

我的email.js文件(正如您所看到的,我已经注释了一些尝试隔离问题的内容):

/* 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
            };
        }]);


})();

1 个答案:

答案 0 :(得分:2)

根据您提供的代码,您的config注射中未定义authFactory

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