Answer the question
In order to leave comments, you need to log in
How to create a service available in the config section and beyond?
It is necessary to make a simple configuration service (several string values), which then users of the module will be able to edit both in the config section, and further at any time. Something like a service of the Value type, but with the ability to use it in the config section as well.
Answer the question
In order to leave comments, you need to log in
Register a constant service, such as a string, a number, an array, an object or a function, with the $injector. Unlike value it can be injected into a module configuration function (see angular.Module) and it cannot be overridden by an Angular decorator.angular.module('example').constant('config', {foo: 'bar'});
angular.module('example', [])
.provider('MyService', function ($logProvider){
var var1, var2;
this.setVar1 = function(value){ var1 = value; };
this.setVar2 = function(value){ var2 = value; };
this.$get = function ($q){
return new MyService();
function MyService(){
this.returnSomething = function (){
return $q.when('something ' + var1);
};
}
};
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question