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