0
我想将所有常量存储在一个地方,并在需要的地方注入此模块。使用当前模块服务中其他模块的常量
constant.js
(function(){
var constantModule = angular.module('Constants',[]);
constantModule.constant('AppDefaults',{
DEFAULT_PAGE_SIZE : 100
});
}());
,并使用这个常量在这里另一个模块:
var app = angular.module('app',['Constants']);
app.controller('AppController',function($scope,AppService){
$scope.someMethod = function() {
var response = AppService.doSomething();
}
});
app.service('AppService',['$http', '$q','Constants',function($http,$q,Constants){
return({
doSomething:doSomething
});
function doSomething() {
method: "post",
url: "/foo/bar",
data: {
pageSize: Constants.AppDefaults.DEFAULT_PAGE_SIZE
}
}
}]);
但我的角度不能注入常量到服务。有没有解决的办法 ?
那么这是令人尴尬的,但谢谢。 – Hav3n