Una costante può essere iniettata ovunque.
Una costante non può essere intercettata da un decoratore, che significa che il valore di una costante non dovrebbe mai essere modificato.
var app = angular.module('app', []);
app.constant('PI', 3.14159265359);
app.config(function(PI){
var radius = 4;
//PI can be injected here in the config block
var perimeter = 2 * PI * radius;
});
app.controller('appCtrl', function(PI) {
var radius = 4;
// calculate area of the circle
var area = PI * radius * radius;
});
valore differisce da costante in quel valore non può essere iniettata in configurazioni, ma può essere intercettato da decoratori.
var app = angular.module('app', []);
app.value('greeting', 'Hello');
app.config(function ($provide) {
$provide.decorator('greeting', function ($delegate) {
return $delegate + ' World!';
});
});
fonte
2015-05-19 14:08:10
fantastico tutorial http://ilikekillnerds.com/2014/11/constants-values-global-variables-in-angularjs-the-right-way/ – vineet