在 Angular unpr 错误上拔掉了我所有的头发



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

})();

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

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

最新更新