作用
顾名思义,就是定义常量 Module.constant(key, value) is used to inject a constant value
如何使用
var app = angular.module('app', []);
app.value('myValue', 'weee');
// use it in a service
myService.$inejct = ['myValue'];
function myService(myValue){
return {
whatsMyThing: function() {
return myValue; //weee
}
};
}
// use it in a controller
app.controller('someController', someController);
someController.$inject = ['myValue'];
function someController(myValue) {
var vm = this;
vm.foo = myvalue;
}
参考
https://docs.angularjs.org/api/auto/service/$provide http://stackoverflow.com/questions/13015523/angular-js-is-value-the-proper-way-to-set-app-wide-constant-and-how-to-retri