1

In angular DOC

Register a value service with the $injector, such as a string, a number, an array, an object or a function. This is short for registering a service where its provider's $get property is a factory function that takes no arguments and returns the value service.

In the bold text, that says $get property is a factory function that takes no arguments, I know about the $get function in a angular providers which will be invoked using $injector.invoke() when an instance needs to be created and it is must have a $get function in a provider.

my question is about what is the underlying meaning of function that takes no arguments?

much appreciate if someone can describe the inner pieces of the angular values service & factory service with comparing both with the above doc quote. Thanks.

Kalhan.Toress
  • 21,683
  • 8
  • 68
  • 92

1 Answers1

0

It means angular is creating a provider, like any other, that returns the value you're passing to it with module.value('name', value);. This type of provider is appropriate when there is no logic involved in building the value, and no dependency on some other service.

Comparison, yielding same result:


angular.module('myApp')
    .value('baseUrl', 'http://localhost:8080/');

angular.module('myApp')
    .factory('baseUrl', baseUrlFactory);

function baseUrlFactory(){
    return 'http://localhost:8080/';
}
nbering
  • 2,725
  • 1
  • 23
  • 31