angularjs:无法注入工厂

时间:2015-03-26 10:47:23

标签: angularjs

我有一家工厂,

var commonFactories = angular.module('commonFactories', []).
factory('acampaign', function () {
    // return {'a' : 1};
    return "hello";
});

我将它注入模块,

angular.module("campaign", ["ngRoute", "ngResource", "commonServices", "commonFactories"]).
// configure campaign module
config(["acampaign", function(acampaign) {

...

}

Angular抛出错误,说它无法实例化campaign模块,

Failed to instantiate module campaign due to:
Error: [$injector:unpr] http://errors.angularjs.org/1.3.12/$injector/unpr?p0=acam...
    at Error (native)
    at http://localhost:8000/static/assets/angularjs/angular.min.js:6:417
    at http://localhost:8000/static/assets/angularjs/angular.min.js:38:7
    at d (http://localhost:8000/static/assets/angularjs/angular.min.js:36:13)
    at Object.e [as invoke] (http://localhost:8000/static/assets/angularjs/angular.min.js:36:283)
    at d (http://localhost:8000/static/assets/angularjs/angular.min.js:34:498)
    at http://localhost:8000/static/assets/angularjs/angular.min.js:35:99
    at s (http://localhost:8000/static/assets/angularjs/angular.min.js:7:302)
    at g (http://localhost:8000/static/assets/angularjs/angular.min.js:34:399)
    at ab (http://localhost:8000/static/assets/angularjs/angular.min.js:38:135

1 个答案:

答案 0 :(得分:1)

您的acampaign工厂是配置功能中的acampaignProvider。工厂和服务本质上是供应商的糖语法。请查看guide提供商配方部分

中的提供商