【发布时间】:2015-05-13 16:13:44
【问题描述】:
我有一个模块 (app.config) 我想注入我的整个应用程序。
该模块需要在注入应用的所有其他模块中都可以访问
例如,我的应用如下所示:
angular.module('myApp', [
'app.config',
'module#1',
'module#2',
'module#3',
'module#4'
])
.config...
//////////////////////////////
这里是 app.config
angular.module('app.config', []).
constant('NAME1', 'Name1').
constant('NAME2', 'Name2');
////////////////////
我希望以这样一种方式注入“app.config”,使其也可以在所有模块(module#1'、'module#2'、....)中访问。
这是我的问题:
angular.module('module#1', []).
service('serviceOne', serviceOne);
function ServiceOne($http) {
var service = {
getMyProfile: function(){return $http.get('api/' + NAME1);}
};
return service;
}
问题 -> NAME1 未定义。 但我以为我将它注入到整个应用程序中???
我不想将 app.config 单独注入每个模块。还有其他解决方案吗?
【问题讨论】:
标签: angularjs angular-services