2014-09-28 132 views
1

MY主控制器错误:错误:unpr未知提供商

var MyApp = angular.module('ionicApp', ['ionic', 'MobiNav', 'authFactory']); 

控制器,功耗厂

MyApp.controller('AuthUser', ['$scope', 'authFactoryService', function ($scope, authFactoryService) { 
    $scope.showForm = true; 
    $scope.UserDataLogin = function() { 
     var loginData = {}; 
     $scope.registration = { 
      userName: $scope.Auth.userName, 
      password: $scope.Auth.password, 
      confirmPassword: $scope.Auth.password 
     }; 
     authFactoryService.SaveRegistration(registration); 
     window.scope = loginData; 
    }; 
} 
] 
); 

这是单独的文件工厂

var AuthService = angular.module('authFactory', []); 
AuthService.factory('authFactoryService', [ 
    '$http', '$q', '$scope', function ($http, $q, $scope) { 
    return { 
     SaveRegistration: function() { 
      var urlBase = 'http://localhost:48868/'; 
      $http.post(urlBase + 'api/account/register', registration).then(function(response) { 
        $scope.savedSuccessfully = true; 
        $scope.message = "User has been registered successfully, you will be redicted to login page in 2 seconds."; 
       }, 
       function(response) { 
        var errors = []; 
        for (var key in response.data.modelState) { 
         for (var i = 0; i < response.data.modelState[key].length; i++) { 
          errors.push(response.data.modelState[key][i]); 
         } 
        } 
        $scope.message = "Failed to register user due to:" + errors.join(' '); 
       }); 
     } 

    }; 
}]); 

错误,那么我得到 错误:[$ injector:unpr] http://errors.angularjs.org/1.2.17/ $ injector/unpr?p0 = copeProvider%20%3C-%20%在错误(原生)24scope%20%3 C-%20authFactoryService

为什么它是无法加载authFactoryService服务

回答

3

终于想通了挖, $范围再次在工厂 注入更换 这

AuthService.factory('authFactoryService', [ 
    '$http', '$q', '$scope', function ($http, $q, $scope) {}]); 

这个(只是删除了$范围这再次注入工厂依赖。

AuthService.factory('authFactoryService', [ 
     '$http', '$q', function ($http, $q, $scope) {}]); 
1

var AuthService = angular.module('authFactory', []);

您在模块中indlcuded的空数组。这使其成为 模块设置器,覆盖现有模块。 获取您使用angular.module('authFactory')<的模块 - 注意缺少的第二个参数。

问候 桑德

+0

i如上尝试 我收到以下错误消息。未捕获的错误:[$ injector:nomod] http://errors.angularjs.org/1.2.17/$injector/nomod?p0=authFactory – 2014-09-28 09:13:32

相关问题