AngularJS常量

13 浏览
0 Comments

AngularJS常量

在AngularJS中,是否可能将一个常量注入到另一个常量中?

例如:

var app = angular.module('myApp');

app.constant('foo', { message: "Hello" } );

app.constant('bar', ['foo', function(foo) {

return {

message: foo.message + ' World!'

}

}]);

我需要使用一个Angular常量,因为我需要将其注入到一个配置函数中。即:

app.config(['bar', function(bar) {

console.log(bar.message);

}]);

我知道你只能将常量和提供者注入到配置函数中,我了解到可以在提供者中进行依赖注入,但是这似乎不是这种情况下最好的方法...

提前感谢你的帮助!

0