错误:错误:未知未知提供者

我的主控制器

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%3C-出错时的%20authFactoryService(本机)

为什么它无法加载authFactoryService服务


最后图挖了, $ Scope再次被Factory注入替换掉了

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

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

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

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

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

问候桑德

链接地址: http://www.djcxy.com/p/77661.html

上一篇: Error: error:unpr Unknown Provider

下一篇: Inject angular directive and service. [$injector:unpr] error