1

所以我得到一个角度 [$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
            };
        }]);


})();
4

1 回答 1

2

从您给出的代码来看,您的注入config中似乎没有定义。authFactory

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

于 2016-06-07T15:44:56.513 回答