错误:[$ injector:unpr](不是通过缩小,双模块实例化)

时间:2015-04-20 15:34:17

标签: javascript angularjs

我正在努力解决这个错误很长一段时间,我浏览了很多堆栈和其他论坛。 我知道这个错误意味着它无法找到服务,但为什么呢? 我在依赖项数组中写了它... 我认为这可能与模块范围有关,但我无法理解它是如何工作的。

这是来自控制台的完整错误:

angular.js:12007Error: [$injector:unpr] http://errors.angularjs.org/1.4.0-rc.0/$injector/unpr?p0=userAccountProvider%20%3C-%20userAccount%20%3C-%20RegisterController
at Error (native)
at https://code.angularjs.org/1.4.0-rc.0/angular.min.js:6:421
at https://code.angularjs.org/1.4.0-rc.0/angular.min.js:39:288
at Object.d [as get] (https://code.angularjs.org/1.4.0-rc.0/angular.min.js:37:266)
at https://code.angularjs.org/1.4.0-rc.0/angular.min.js:39:362
at d (https://code.angularjs.org/1.4.0-rc.0/angular.min.js:37:266)
at e (https://code.angularjs.org/1.4.0-rc.0/angular.min.js:38:26)
at Object.instantiate (https://code.angularjs.org/1.4.0-rc.0/angular.min.js:38:175)
at $get (https://code.angularjs.org/1.4.0-rc.0/angular.min.js:78:405)
at link (https://code.angularjs.org/1.4.0-rc.0/angular-route.min.js:7:268) <div ng-view="" class="ng-scope">(anonymous function) @ angular.js:12007$get @ angular.js:8867aa @ angular.js:8418M @ angular.js:7925g @ angular.js:7326(anonymous function) @ angular.js:7200$get.g @ angular.js:7345m @ angular.js:7952x @ angular-route.js:935$get.m.$broadcast @ angular.js:15784(anonymous function) @ angular-route.js:618(anonymous function) @ angular.js:14238$get.m.$eval @ angular.js:15465$get.m.$digest @ angular.js:15276$get.m.$apply @ angular.js:15570l @ angular.js:10057O @ angular.js:10229w.onload @ angular.js:10170

这是给出错误的代码:

    (function(){

    var app = angular.module('intelAgent');

    var RegisterController = function($scope,$log,userAccount,currentUser){

        $scope.isLoggedIn = function(){
            return currentUser.getProfile().isLoggedIn;
        };
        $scope.message = "";
        $scope.userData = {
                username: '',
                email: '',
                password: '',
                confirmPassword: ''
                };


        $scope.registerUser = function (){
                //send the registeration data to db using our webAPI
                userAccount.registration.registerUser($scope.userData,
                    function(data){//on Success
                        $scope.confirmPassword = "";
                        $scope.message = "Registartion...";
                        $scope.login();
                        },
                        function(response){//on Failure
                            $scope.isLoggedIn = false;
                            $scope.message = response.statusText + "/r/n";
                            if(response.data.exceptionMessage)
                                $scope.message += response.data.exceptionMessage;

                            if(response.data.modelState){
                                for(var key in response.data.modelState){
                                    $scope.message += response.data.modelState[key] + "/r/n";
                                }
                            }
                        });
            };
        $scope.login = function(){
            $scope.userData.grant_type = "password";
            $scope.userData.userName = $scope.userData.email;

            userAccount.login.loginUser($scope.userData,
                function(data){//on Success
                    $scope.message = "";
                    $scope.password = "";
                    currentUser.setProfile($scope.userData.email,token,true);//init current user profile
                },
                function(response){//on Failure
                    $scope.password ="";
                    currentUser.setProfile("","",false);//reset current user
                    $scope.message = response.statusText + "/r/n";
                    if(response.data.exceptionMessage)
                        $scope.message += response.data.exceptionMessage + "/r/n" ;
                    if(response.data.error)
                        $scope.message += response.data.error + "/r/n";
                });
        }
    };
    app.controller('RegisterController',["$scope","$log",'userAccount',"currentUser",RegisterController]);//required dependencies
}());

这是找不到的提供商。

(function() {
  var moduleRef = angular.module("services");
  var userAccount = function(appSettings,$resource) {

        return {
            registration: $resource(appSettings.serverURL + "/api/Account/Register",null,{
                'registerUser':{ method: 'POST'}
            }),
            login: $resource(appSettings.serverURL + "/Token",null,{
                'loginUser':{ 
                    method: 'POST',
                    headers: { 'Content-Type': 'application/x-www-form-urlencoded'},
                    transformRequest: function (data, headersGetter){//transform to URL encoded
                        var str = [];
                        for(var d in data)
                            str.push(encodeURIComponent(data[d]));
                        return str.join("&");
                    }
                }
            }
        )};
    }
  moduleRef.factory("userAccount", ["appSettings","$resource",userAccount]);//use this dependencies
}()); 

Index.html srces

    <!--App JS-->
    <script src="js/app.js"></script>
    <script src="js/MainController.js"></script>
    <script src="js/LoginController.js"></script>
    <script src="js/ActionController.js"></script>
    <script src="js/RegisterController.js"></script>
    <!--Services JS-->
    <script src="services/appSettings.js"></script>
    <script src="services/userAccount.js"></script>
    <script src="services/currentUser.js"></script>
  </head>

我认为这就是你所需要的,但如果需要更多信息,请告诉我! 我很乐意提供它。

抱歉我的角色无知:)。

0 个答案:

没有答案