从AngularJS中的另一个子模块访问工厂

时间:2014-11-26 17:18:59

标签: angularjs angularjs-scope angularjs-factory

关于这方面还有更多问题,但我似乎无法找到我特定问题的答案。

我在AngularJS应用程序中使用了很多子模块。有时我想使用以前在另一个子模块中创建的现有工厂。

angular.module('app', ['users','login']);

angular.module('users', [])
.factory('UserFactory', function($http) {
    return {
        create: function() {
            return {};
        }
    };
});

angular.module('login', ['users'])
.controller('LoginCtrl', function(UserFactory) {
    UserFactory.create();
});

当我使用此代码刷新我的应用程序时,它将触发错误:

  

错误:[$ injector:unpr] http://errors.angularjs.org/1.3.4/ $ injector / unpr?p0 =%24scopeProvider%20%3C-%20%24scope%20%3C-%20UserFactory   Z /

1 个答案:

答案 0 :(得分:0)

发现问题。在发布此处之前清除我的代码的愚蠢错误和愚蠢的想法!

在实际代码中,我将$scope添加到工厂。

当我删除$scope时,一切正常......